Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2016-10-28 11:50 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.