in reply to split (grep)
which prints:use warnings; use strict; my @foo = qw/tom steve bill roger bob/; my %bar = (roger => 99, steve => 56, ted => 88, tom => 54); for my $name (@foo) { print "$name : $bar{$name} \n" if exists $bar{$name}; }
I understand that you are reading your data from files, so populating a hash is not more complicated than filling an array. You just have to do the split before populating the hash, instead of doing it later.tom : 54 steve : 56 roger : 99
Actually, even with a short list, I think that I would probably prefer the hash-based solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split (grep)
by tbone654 (Beadle) on Oct 23, 2014 at 21:30 UTC | |
by tbone654 (Beadle) on Oct 24, 2014 at 18:33 UTC |