You can use the hash. Use the values ββfrom the first array as keys to the values ββtaken from the second array. Then just do foreach my $key ( sort keys %the_hash) { do stuff } . If the key values ββare not unique, then the hash of the arrays and clicking the values ββinto the hash file are used.
#! perl use strict; use warnings; my @key_data = ('1', '6', '8', '4', '5', '4', '5'); my @val_data = ('a', 'c', 'd', 'f', 'w', 'z', 'w'); my %the_hash; for ( my $ii=0; $ii<=$#key_data; $ii++) { push @{$the_hash{$key_data[$ii]}}, $val_data[$ii]; } for my $key ( sort keys %the_hash ) { print "key $key\n"; foreach my $val ( @{$the_hash{$key}} ) { print " $val\n"; } }
source share