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

Re^2: Use of "my" after Perl v5.14

by 2teez (Priest)
on Sep 21, 2012 at 02:21 UTC ( #994798=note: print w/ replies, xml ) Need Help??


in reply to Re: Use of "my" after Perl v5.14
in thread Use of "my" after Perl v5.14

Had the declaration been "my $n = 0", then for every subroutine call it would start with 0...

Depending on where "my $n = 0" was placed and how.
Using "my $n = 0" outside the subrourtine, placed in a block like so:

for (1..5){marine()}; { my $n=0; # private, persistent variable $n sub marine { $n += 1; print "Hello, sailor number $n!\n"; } }
will work exactly, like using:
use 5.010; for (1..5){marine()}; sub marine { state $n = 0; # private, persistent variable $n $n += 1; print "Hello, sailor number $n!\n"; }

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re^2: Use of "my" after Perl v5.14
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2014-07-31 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls