in reply to grep help

It's an okay way, but you don't really need regular expressions to match the haircolor or the firstname, since you're just matching string constants ("brown" and "j").

And since the keys are just indices, it's probably better to use an array:

my @friends; for (@raw_list) { my @friend = split /,/; push @friends, { FIRSTNAME => $friend[0], LASTNAME => $friend[1], HAIRCOLOR => $friend[2] }; } my @results = grep { lc $_->{HAIRCOLOR} eq 'brown' and 'j' eq substr(lc $_->{FIRSTNAME}, 0, 1) } @friends;

The new line in the grep block, is, of course, only a style decision.


Update: Yes, I have tried it, and it works for me. What error is it giving?

Update 2: You've changed the format of the input file.

When splitting, spaces matter. Have you tried your own code with "john, smith, brown"? It doesn't work.

Anyhow, replace the split statement above with split /\s*,\s*/


[ ar0n -- want job (boston) ]

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.