Thread Array vergleichen
(7 answers)
Opened by wandasia at 2007-07-10 12:56 Code (perl): (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 #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array1 = ("A","A","A","B","C"); my @array2 = ("a","b","c","d","e"); my %seen; my @tmp; for my $i ( 0.. $#array1 ){ push @tmp, $array1[$i] unless exists $seen{ $array1[$i] }; push @{ $seen{ $array1[$i] } }, $i; } @array1 = @tmp; undef @tmp; for my $j ( 0..$#array1 ){ my $elem = $array1[$j]; $tmp[$j] = join '', @array2[ @{ $seen{$elem} } ]; } @array2 = @tmp; print Dumper \@array1, \@array2; 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/ |