Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: foreach with array elements problem

by donarb (Beadle)
on Oct 22, 2005 at 18:48 UTC ( #502241=note: print w/replies, xml ) Need Help??


in reply to Re^2: foreach with array elements problem
in thread foreach with array elements problem

To answer the original question, why is it a syntax error?

Going back to perlsyn, here's what it says about the variable in a foreach loop:

If the variable is preceded with the keyword my, then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop.

So even though $array[0] is a scalar value, it cannot exist because there is no local version of @array within the loop. Even if there were a local version of @array within the loop, you would still have to copy those values to the external version of @array from within the loop.
  • Comment on Re^3: foreach with array elements problem

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-01-16 10:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?