Errin Larsen wrote:
Hi all, straight out of the Learning Perl book (3rd edition, page
275) is this code:

my @numbers;
push @numbers, split while <>;
foreach (sort { $a <=> $b } @numbers) {
   printf "%20g\n", $_;
}

This works flawlessly.  My question is why can't I put that
variable declaration in the push function?  like this:

push my @numbers, split while <>;
foreach (sort { $a <=> $b } @numbers) {
   printf "%20g\n", $_;
}

Because the push() statement is in a loop, and my() would empty the variable at each iteration.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to