in reply to Re: specific array in hash of arrays
in thread specific array in hash of arrays
moritz explained, so what follows is a solution. Basically, comparing a single value against an array makes so sense. By using grep, the value can be compared against every element of the array.
#!/usr/bin/perl use strict; use warnings; my %hoa = ( arraya => [qw( dd1 dd2 dd3 dd4 )], arrayb => [qw( gg1 gg2 gg3 gg4 )], arrayc => [qw( cc1 cc2 cc3 cc4 )], ); chomp( my $array_name = <STDIN> ); # e.g. arraya chomp( my $to_find = <STDIN> ); # e.g. dd2 if ( exists( $hoa{$array_name} ) && grep { $_ eq $to_find } @{$hoa{$array_name}} ) { print( @{$hoa{$array_name}}, "\n" ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: specific array in hash of arrays
by gone2015 (Deacon) on Oct 09, 2008 at 13:54 UTC | |
by ikegami (Patriarch) on Oct 09, 2008 at 14:11 UTC | |
by gone2015 (Deacon) on Oct 09, 2008 at 15:01 UTC | |
by ikegami (Patriarch) on Oct 09, 2008 at 15:21 UTC | |
|
Re^3: specific array in hash of arrays
by kwn (Novice) on Oct 09, 2008 at 11:23 UTC |