Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by marinersk (Curate)
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__

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 surveying the Monastery: (6)
As of 2016-06-26 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (329 votes). Check out past polls.