in reply to Comparing values within a Hash of Arrays
You can't use exists in this case, as you are not looking to see if a hash key exists, you need to check within the array to see if an element exists. Here's an example of what I think you want to achieve:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use List::Util qw( first ); my @array1 = ( "proc1", "proc2", "proc3", "proc4" ); my @array2 = ( "proc1", "proc2", "proc3", "proc4", "proc5" ); my %HoA = ( prebuilds => [@array1], postbuilds => [@array2], ); for my $postbuild ( @{ $HoA{ postbuilds } } ){ print "$postbuild: "; if ( first { $_ =~ $postbuild } @{ $HoA{ prebuilds } } ){ print "yes\n"; } else { print "no\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Comparing values within a Hash of Arrays
by TJRandall (Sexton) on Apr 24, 2012 at 14:30 UTC | |
by stevieb (Canon) on Apr 24, 2012 at 14:34 UTC | |
by TJRandall (Sexton) on Apr 24, 2012 at 15:36 UTC |