Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004998]
help
Chatterbox?
davido just discovered less +F and wonders why tail -f is the more commonly used tool.
[afoken]: tail is way older than less
erix likes multitail

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (4)
As of 2017-01-17 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (158 votes). Check out past polls.