Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: grep and $_

by grep (Monsignor)
on Aug 11, 2007 at 23:26 UTC ( #631983=note: print w/replies, xml ) Need Help??

in reply to grep and $_

In your case, $_ is an alias (think pronoun) for the current list value being iterated in the closest loop.

I think the main problem you are having is the implicit loop that grep creates. grep actually creates another loop which sets $_.

Also your outside loop over @required never sets $_ since you explicitly create a variable.


my @required = qw(preserver sunscreen water_bottle jacket); foreach my $item (@required) { print "$_\n"; ## You just get a warning }

Replies are listed 'Best First'.
Re^2: grep and $_
by convenientstore (Pilgrim) on Aug 11, 2007 at 23:38 UTC
    no wonder I coudn't print $_
    thanks guys
      you can if you use the BLOCK form of grep..
      unless ( grep { print "$item eq $_? ", $item eq $_, "\n"; $item eq $_; } @skipper ) { # not found in list? print "skipper is missing $item.\n"; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://631983]
LanX though probably produced outside Holywood
[Your Mother]: There are tons of good movies from all over but for every gem there is a pile of dirt 10 meters high burying it.
[LanX]: well
[LanX]: who's Jamie Earl?
[Your Mother]: Also: I am old and complaining is my hobby.
[LanX]: BTW: have you ever seen Network?
[Your Mother]: Sorry: Jackie Earle Haley
[Eily]: Sturgeon's law Your Mother?
[Your Mother]: Network, the 70's movie? Yes. Wonderful. Though it's been 20 years. Time to do it again.
[Your Mother]: I miss the Sci-Fi authors of that era quite a lot...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2018-03-19 15:00 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.