Your code, as you posted, does not work. Your hash, %friends has the same hash reference in all its values. Why? Because you didn't declare $sucker as a lexical; if you understand the consequences, you'd know why you'd have to.
Your use of regexes can be totally wiped out, and in particular, your regex /^j.*/i goes overboard and could merely have been /^j/.
You're sorting the keys of %friends, which all happen to be numbers, but would end up being sorted ASCIIbetically instead of numerically, so the keys would be (1,10,11,12, ... ,2,20,21, ... ,3,4, ...). You probably don't want that. You should be using an array instead of a hash.
Here is how I would write your code.
Don't insult my friends. That's a ground rule here.my (@friends, @results); for (@raw_list) { my %who; @who{qw( FIRSTNAME LASTNAME HAIRCOLOR )} = split /,/; push @friends, \%who; } @results = grep { lc($_->{HAIRCOLOR}) eq 'brown' and lc(substr($_->{FIRSTNAME})) eq 'j' } @friends;
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
In reply to Re: grep help
by japhy
in thread grep help
by sickboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |