[oak perl] my operator question
Sandy Santra
santranyc at yahoo.com
Tue Mar 8 04:38:47 PST 2005
Following up on Zed's answer to George's "simple problem,"
why does this work:
my @numbers = qw(1 4 6);
$total += $_ for @numbers;
print $total;
but not this:
use strict;
my @numbers = qw(1 4 6);
my $total = 0;
$total += $_ for @numbers;
print $total;
[Global symbol "$total" requires explicit package name at test line 3.
Global symbol "$total" requires explicit package name at test line 4.]
and adding "my" this way doesn't work either:
use strict;
my @numbers = qw(1 4 6);
my $total += $_ for @numbers;
print $total;
[it prints nothing]
--Sandy Santra
More information about the Oakland
mailing list