Perl SemiPrivate Variables in Function - Perl Views : 250
Tagged in : Perl
0 0
Send mail

Perl SemiPrivate Variables in Function


The local operator is used to define variables of any type that are private to the subroutine there are defined in and any subroutine called within the defininf subroutine.

$value = "original";

tellme();
spoof();
tellme();

sub spoof {
local ($value) = "temporary";
tellme();
}

sub tellme {
print "Current value is $value\n";
}

This code cause the sub tellme to be executed 3 times, printing the results as follows...

first time, prints "original"
second time, prints "temporary"
third time, prints "original"

By Geethalakshmi, On - 2010-09-17



    Login to add Comments .