Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: grep {CONSTANT} @list

by tobyink (Abbot)
on Nov 21, 2012 at 20:08 UTC ( #1004998=note: print w/ replies, xml ) Need Help??


in reply to grep {CONSTANT} @list

Nothing to do with grep in particular, or constants.

use constant REGEXP => qr(a); print grep { REGEXP } qw(a b c);

... is equivalent to:

my @tmp; foreach (qw(a b c)) { push @tmp, $_ if qr(a); } print @tmp;

See the problem now? if qr(a) is always true. if qr(anything) is always true.

Try:

print grep { $_ =~ REGEXP } @list;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: grep {CONSTANT} @list
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004998]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-07-29 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (211 votes), past polls