Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Playing with non-localized $_ in nested loops.

by ysth (Canon)
on Aug 23, 2004 at 04:22 UTC ( [id://385005]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Playing with non-localized $_ in nested loops.
in thread Playing with non-localized $_ in nested loops.

The automatic setting of $_ comes from the combination of while() and readline. Just a plain readline won't do it. Nor does while with just any operator do the implicit assignment.
  • Comment on Re^3: Playing with non-localized $_ in nested loops.

Replies are listed 'Best First'.
Re^4: Playing with non-localized $_ in nested loops.
by davido (Cardinal) on Aug 23, 2004 at 04:36 UTC
    <DATA>; print $_; __DATA__ This is a test. __OUTPUT__ Use of uninitialized value in print at mytest.pl line 8, <DATA> line 1 +.

    Hmm... You're right. There goes that theory. ;) I was erroneously sure that the while() loop's conditional had nothing to do with the fact that the diamond operator feeds $_. Thanks for the enlightenment. :D


    Dave

      There are actually two pieces of dwimmery going on; first, if a readline or a glob is the only thing in a while condition (whether a statement modifier or while statement), it gets an implicit $_ =. Next, if a while condition is a scalar assignment from a readline, readdir, glob, or each, the whole condition gets an implicit defined() wrapped around it, so the loop continues on "0" or "".

      That is why, in the node you referenced, I was talking about while(<FH>). Invoking the DWIMmery really does require this entire combination of operations.

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (1)
As of 2024-04-19 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found