Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: variable like $_

by JavaFan (Canon)
on Feb 04, 2009 at 10:06 UTC ( [id://741224]=note: print w/replies, xml ) Need Help??


in reply to Re: variable like $_
in thread variable like $_

There is only one $_
True.
and the second use of it destroys the contents of the first use.
False.
foreach ("a", "b") { # First use of $_ foreach ("c", "d") { # Second use of $_ say; } say; # 'Old' value of $_ } __END__ c d a c d b
The second use of '$_' doesn't destroy the content of the first use. It stores it somewhere else, and restores the value after the second use is finished. That's the principle of local. And that's what's happening with a foreach loop.

Replies are listed 'Best First'.
Re^3: variable like $_
by CountZero (Bishop) on Feb 07, 2009 at 14:47 UTC
    "Destroy was indeed not the right word, "hide" or "shadow" would have been better.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 01:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found