P
Prabh
Hello all,
Is it possible to access a variable with local scope in a subroutine
from outside of the subroutine?
e.g.,
#usr/local/bin/perl
use strict ;
use warnings ;
sub testScope
{
my $var = 10 ;
}
&testScope ;
print "$var\n" ;
==========================================
It doesnt compile with 'use strict', after removing strict, I get
blank from the print.
Is it possible to retrieve $var in some 'testScope::$var' fashion?
I realize I could add "return $var;" to the subroutine and access it
from the out, but was just curious if its possible to access
variables.
If I dont use "my" or "strict" I can.
If its a frowned-upon practice, then why does Perl allow it in the
first place?
Thanks for your time,
Prab
Is it possible to access a variable with local scope in a subroutine
from outside of the subroutine?
e.g.,
#usr/local/bin/perl
use strict ;
use warnings ;
sub testScope
{
my $var = 10 ;
}
&testScope ;
print "$var\n" ;
==========================================
It doesnt compile with 'use strict', after removing strict, I get
blank from the print.
Is it possible to retrieve $var in some 'testScope::$var' fashion?
I realize I could add "return $var;" to the subroutine and access it
from the out, but was just curious if its possible to access
variables.
If I dont use "my" or "strict" I can.
If its a frowned-upon practice, then why does Perl allow it in the
first place?
Thanks for your time,
Prab