Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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

by marinersk (Chaplain)
on Sep 20, 2012 at 22:12 UTC ( #994766=note: print w/ replies, xml ) Need Help??


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

Consider this (notably, the difference between $localPrivateVarX and $localPersistentY):

#!/usr/bin/perl use strict; my $GlobalA = 1; foreach my $notAGlobalB (qw /X Y Z/) { &displayDashedLine(); my $returnValueFromM = &subM($notAGlobalB); print "Return: \$GlobalA = '$GlobalA', \$notAGlobalB = '$notAGlob +alB', \$returnValueFromM = '$returnValueFromM'\n"; my $returnValueFromN = &subN($notAGlobalB); print "Return: \$GlobalA = '$GlobalA', \$notAGlobalB = '$notAGlob +alB', \$returnValueFromN = '$returnValueFromN'\n"; } &displayDashedLine(); exit; sub displayDashedLine { print "----------------------------------------\n"; } sub subM { my ($parameterM1, @everythingElse) = @_; my $localPrivateVarX; if (!defined $localPrivateVarX) { $localPrivateVarX = 0; } $localPrivateVarX++; print " SubM: \$GlobalA = '$GlobalA', \$parameterM1 = '$paramete +rM1', \$localPrivateVarX = '$localPrivateVarX'\n"; return; } { my $localPersistentY; sub subN { my ($parameterN1, @everythingElse) = @_; if (!defined $localPersistentY) { $localPersistentY = 0; } $localPersistentY++; print " SubN: \$GlobalA = '$GlobalA', \$parameterN1 = '$para +meterN1', \$localPersistentY = '$localPersistentY'\n"; return; } } exit; __END__


Comment on Re: Use of "my" after Perl v5.14
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-09-19 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (145 votes), past polls