[oak perl] my operator question

Jon Seidel, CMC jseidel at edpci.com
Tue Mar 8 08:08:34 PST 2005


I'm guessing it has something to do with the "for numbers" construct
actually expecting an array context...?

Good question...jon

> 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
>
> _______________________________________________
> Oakland mailing list
> Oakland at pm.org
> http://mail.pm.org/mailman/listinfo/oakland
>



-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

      Connecting Business and Technology

Jon Seidel, CMC                   +1-510-530-6314
EDP Consulting, Inc.                www.edpci.com

CMC (Certified Management Consultant) is a certification mark awarded by
the Institute of Management Consultants USA and represents evidence of the
highest standards of consulting and adherence to the ethical canons of the
profession. Less than 1% of all consultants have achieved this level of
performance. See www.imcusa.org/hireacmc.acgi.



More information about the Oakland mailing list