Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: How do I localize $_ in while loops?

by ajdelore (Pilgrim)
on Jul 21, 2003 at 23:51 UTC ( [id://276542]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    foreach (qw/foo bar/) {
      print;
      print foreach (qw/one two three/);
    }
    # output: fooonetwothreebaronetwothree
    
  2. or download this
    foreach (qw/foo bar/) {
      print;
    ...
      print while (shift @list); 
    }
    # output: foofoofoofoobarbarbarbar
    
  3. or download this
     
    foreach (qw/foo bar/) {
      print;
    ...
      print while (local $_ = shift @list); 
    }
    # output: fooonetwothreebaronetwothree
    
  4. or download this
    { local $_; print while (shift @list); }
    
  5. or download this
    # will not localize $_ to the while loop
    local $_; print while (shift @list);
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found