Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Scoping of my with foreach loop

by ikegami (Patriarch)
on Mar 07, 2005 at 19:24 UTC ( [id://437291]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    use strict;
    my @array = (1, 2, 3);
    my $item = 'z';
    foreach $item (@array) {}
    print($item);  # Prints 'z' (not '3'!!!).
    
  2. or download this
    use strict;
    my @array = (1, 2, 3);
    foreach my $item (@array) {}
    print($item);  # Compile error. $item only in scope for loop.
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-03-19 04:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found