Using local : Local « Subroutine « Perl






Using local

   

sub printifOK
{
    local $localvalue = $value;

    if ($localvalue > 10 ) {
        print "Value is $value.\n";
    } else {
        print "Value is too small.\n";
    }
}

$value = 10;
printifOK;

$value = 12;
printifOK;

   
    
    
  








Related examples in the same category

1.Local variable shadows the gloabl variable
2.Local variable shadows the global variable in a subroutine
3.Local variables in subroutines
4.Difference between my and local
5.Duplicate global and local variable name (use strict;)