[oak perl] operator question--still confused
Sandy Santra
santranyc at yahoo.com
Tue Mar 8 12:29:20 PST 2005
Thanks for the responses, folks. That was a lot of good
info...unfortunately over my head somewhat.
My problem doesn't involve a loop, merely understanding how "use strict"
and "my" are supposed to work together. I may have copied my examples
incorrectly (sorry!), so they are set forth again here below. I started
out with:
my @numbers = qw(1 4 6);
$total += $_ for @numbers;
print $total;
which worked, producing a value of "11" to my DOS window. Then I decided
to add "use strict;" at the beginning:
use strict;
my @numbers = qw(1 4 6);
$total += $_ for @numbers;
print $total;
That gave me errors, asking me to explicitly define $total (I assume with
"my"). But when I run the following, I get nothing (no return of the value
and no error messages):
use strict;
my @numbers = qw(1 4 6);
my $total += $_ for @numbers;
print $total;
I can't figure out why my first example works, whereas my third doesn't. I
figure this is just something simple I'm missing.
--Sandy Santra
More information about the Oakland
mailing list