in reply to Retrieving Key and Value Hashes
#!/usr/bin/perl # http://perlmonks.org/?node_id=1133207 use strict; $| = 1; my $file1 = <<END; name1 ABCD name2 BCD name3 ASCDA name4 AAAAA END my $file2 = <<END; name1 0.2 name5 0.3 name4 0.0002 name7 0.222 END open my $one, '<', \$file1 or die "$! opening file1"; my %hash1 = split ' ', do{ local $/; <$one> }; close $one; #use YAML; print Dump \%hash1; open my $two, '<', \$file2 or die "$! opengin file2"; while(<$two>) { my ($key) = split; exists $hash1{$key} and print "$key $hash1{$key}\n"; } close $two;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Retrieving Key and Value Hashes
by gghelpneeded (Novice) on Jul 05, 2015 at 00:06 UTC | |
by Anonymous Monk on Jul 05, 2015 at 00:18 UTC | |
|
Re^2: Retrieving Key and Value Hashes
by gghelpneeded (Novice) on Jul 05, 2015 at 00:17 UTC | |
by AnomalousMonk (Archbishop) on Jul 05, 2015 at 01:18 UTC | |
by gghelpneeded (Novice) on Jul 05, 2015 at 03:02 UTC | |
by Laurent_R (Canon) on Jul 05, 2015 at 09:01 UTC | |
by AnomalousMonk (Archbishop) on Jul 05, 2015 at 17:37 UTC | |
by Anonymous Monk on Jul 05, 2015 at 03:42 UTC | |
by gghelpneeded (Novice) on Jul 05, 2015 at 04:46 UTC | |
by Anonymous Monk on Jul 05, 2015 at 00:19 UTC |