in reply to Fast way - get array elements > 4 chars
I didn't want it to be skill test
my @uniq = grep !$seen{$_}++, @words;
preserves order whereas
@seen{@words} = (); my @uniq = keys %seen;
doesn't. It's a well known idiom, not a "skill test". It's even listed in the answer to perldoc -q unique. (See perlfaq4)
wanted to merge with >4 chars
grep length>4, LIST will filter out all items except those with >4 chars, so you end up with
my @long = grep !$seen{$_}++, grep length>4, @words;
or you can combine the two grep calls into one
my @long = grep length>4 && !$seen{$_}++, @words;
|
|---|