choroba,
"You can not change the outer scope from within a sub. If you want to have a global variable, declare it in the topmost scope."
I believe you are referring to "use strict;", but if you run the following code with "# use strict;", you'll see that you can do what the OP wanted.
my $in = result( 3 ); print "my \$in: $in \t \$out: \$out\n"; sub result { our $out = shift; return( 2 ** $out ); }
This also will work in a forked environment, since the global 'our' variable is in the address space of the parent.
However, I would use "use strict;" and predefine the global variables as you stated.
Thank you
"Well done is better than well said." - Benjamin Franklin
In reply to Re^2: Defining global variable in a subroutine
by flexvault
in thread Defining global variable in a subroutine
by bihuboliya
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |