in reply to easy way to extract a hash from an array?
#!/usr/local/bin/perl -w # use strict; our @PEOPLE = (); our $rhFirstNameIdx = {}; our $recCt = 0; while(<DATA>) { chomp; my ($fname, $lname) = split; push @PEOPLE, {fname => $fname, lname => $lname}; push @{$rhFirstNameIdx->{$fname}}, $recCt ++; } our $wanted = 'John'; our @found = @PEOPLE[@{$rhFirstNameIdx->{$wanted}}]; print "First - $_->{fname}, Last - $_->{lname}\n" for @found; __END__ Fred Bloggs Charley Farley John Doe Peter Piper Mary Poppins John Smith Bill Bailey
The little script above illustrates this and prints out the entries for John Doe and John Smith.
Cheers
JohnGG
|
|---|