in reply to
Re: scalar my vs list my
in thread my $var = ''; vs. use constant VAR => '';
Hmm. Nope, you ended up with a few broken ones:
# Local variables: SCALAR,SCALAR,...
my $x, $y, $z;
...
my $filename = "/path/to/file",
$filemode = "immolate",
$opmode = "seek",
$filetype = "image/gif";
Neither of those declare locally anything but the first var.
You'd have to do something like:
my $x, my $y, my $z;
Just think of
my as a really high precedence prefix operator that must
appear before an lvalue, and you'll have the right mental model. But to figure
the scalar-vs-arrayness of the rest of the expression, throw away
all
the my's first.
My preference is one variable per my declaration, unless it's a bunch of scalars and an optional terminating array being fed from a list (like a subroutine argument grab).
-- Randal L. Schwartz, Perl hacker