dirtdog has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks
I'm trying to extract the key,value pair from a hash without first starting from a loop
my %VIS; my $key; my $value; my $mfunds="$ENV{'HOME'}/scripts/MFUNDS.txt"; my $evst="$ENV{'HOME'}/scripts/IN_EVST_NOT_IN_NFS.txt"; open MFUND, $mfunds or die "Can not open $mfunds\n"; while ( <MFUND> ) { chomp; my $aref = [split]; $VIS{$aref->[0]} = $aref->[1]; } open EVST, $evst or die "Can not open config file: $evst\n"; while ( <EVST> ) { chomp; my $aref = [split]; if (exists($VIS{$aref->[0]}) ) { print "$key, $value from %VIS\n"; } }
The code sample of course does not work, because i'm not quite sure how to accomplish the task
$mfunds contains 2 columns of data: a number and a description
$evst would contain 1 column of data: a number
so basically, if the number from $evst exists in $mfunds, then print the key, value (number,desc) from $mfunds
any help would be greatly appreciated
Tony
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Get key and value pair from hash without loop
by tangent (Parson) on Sep 05, 2013 at 16:57 UTC | |
|
Re: Get key and value pair from hash without loop
by hdb (Monsignor) on Sep 05, 2013 at 16:48 UTC |