why doesn't /^$_$/ behave?

S

Sara

OK, $_ is "1", and my aray contains "13", but not "1".

This matches:

grep /^$_$/, @a;

But this doesn't match:

my $xi = $_;
grep /^$xi$/, @a;

p 5.6.1 on RH.
 
J

Jeff 'japhy' Pinyan

[posted & mailed]

OK, $_ is "1", and my aray contains "13", but not "1".

This matches:

grep /^$_$/, @a;

Because in grep() and map(), $_ is locally set to the value in the list
you're looking at. That's why you write

grep /foo/, @a;

because /foo/ is really $_ =~ /foo/.

$_ = 10;
grep print("_ = $_\n"), 1, 2, 3;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top