http://www.perlmonks.org?node_id=778647


in reply to What is it I don't understand about perl scoping?

While I appreciate you may be just using this code to understand how scoping works, the advice I think you really need is quit having these thoughts and expectations, resist. These variables should be passed to the function. Stop running with scissors!
#!/usr/local/bin/perl use strict; my $foo = 1; my $fum = 1; print STDERR "variables are now: $foo $fum\n"; foo($foo, $fum); my $foo = 2; $fum = 2; print STDERR "variables are now: $foo $fum\n"; sub foo { my $foo = shift; my $fum = shift; print STDERR "variables are now: $foo $fum\n"; }