Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > why doesn't /^$_$/ behave?

Thread Tools

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

Posts: n/a
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.
Reply With Quote
Jeff 'japhy' Pinyan
Posts: n/a
[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)

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco 2611 and Cisco 1721 : Why , why , why ????? Cisco 10 05-01-2005 08:49 AM
Why, why, why??? =?Utf-8?B?VGltOjouLg==?= ASP .Net 6 01-27-2005 03:35 PM
Why Why Why You HAVE NO IDEA MCSE 31 04-24-2004 06:40 PM