Thread Arrays und Hashs (15 answers)
Opened by jan10001 at 2004-07-26 10:48

renee
 2004-07-26 11:31
#84929 #84929
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#! /usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my @array = ({key1 => 'value1',
              key2 => 'value2'});
my @array2 = ({key3 => 'value3',
              key4 => 'value4'},
             {key5 => 'value5'});

my @new_array = @{join_arrays(\@array,\@array2)};

print Dumper(\@new_array);

sub join_arrays{
 my ($ar1ref,$ar2ref) = @_;
 my @array = ();
 if(scalar(@{$ar2ref}) > scalar(@{$ar1ref})){
   my $tempref = $ar2ref;
   $ar2ref = $ar1ref;
   $ar1ref = $tempref;
 }
 for(0..(scalar(@{$ar1ref}) - 1)){
   $array[$_] = ${$ar1ref}[$_];
   %{$array[$_]} = (%{$array[$_]},%{${$ar2ref}[$_]}) if(${$ar2ref}[$_]);
 }
 return \@array;
}
\n\n

<!--EDIT|renee|1090827128-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Arrays und Hashs