In fact, declaring these variables as lexical ( my
) variables will not help, because it is too late: the -s
has already set them. It sets global (batch) variables (in your case $main::x
and $main::y
, or - as a special abridged version of $::x
and $::y
). If you do not want to refer to them using your names defined in the package, then you can use our
declaration to indicate that the bare names $x
and $y
refer to $x
and $y
in the current package:
our ($x, $y); print "x: $x\n"; print "y: $y\n";
(Hat-tip to derobert for using our
for this.)
In addition, you can copy global variables to lexical variables with the same name:
my ($x, $y) = ($::x, $::y); print "x: $x\n"; print "y: $y\n";
This will take care of all diagnostic kits.
source share