I am new with PERL and i am having this use case
#global variable
my $global = "foo";
print $global . "\n";
#subroutine call
&change($global);
print $global . "\n";
Here is my subroutine
sub change {
change the value of global to "bar";
return $global;
}
And here is what i want in my output
foo
bar
I know it is basic but i really want to understand the proper way to do this in Perl.
myvariables are, by definition, not global. At most, amyvariable may have file scope.$variable = change($variable);is a much better coding style for most use cases.