Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   why doesn't /^$_$/ behave? (http://www.velocityreviews.com/forums/t883720-why-doesnt-_-behave.html)

Sara 11-18-2003 06:30 PM

why doesn't /^$_$/ behave?
 
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.

Jeff 'japhy' Pinyan 11-18-2003 06:39 PM

Re: why doesn't /^$_$/ behave?
 
[posted & mailed]

On 18 Nov 2003, Sara wrote:

>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;

--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



All times are GMT. The time now is 12:36 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.