Re: declaring with my

2004-09-14 Thread Gunnar Hjalmarsson
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

Re: declaring with my

2004-09-14 Thread John W. Krahn
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

Re: declaring with my

2004-09-14 Thread Gunnar Hjalmarsson
John W. Krahn wrote: Errin Larsen wrote: my @numbers; push @numbers, split while <>; why can't I put that variable declaration in the push function? like this: push my @numbers, split while <>; The original code could be written as: my @numbers; while ( <> ) { push @numbers, split; } Is t

Re: declaring with my

2004-09-14 Thread Errin Larsen
> 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 Hi Gunnar ... Thanks for the help. I assure the list, the following is the code EXACTLY as I was using it to test: #!/u

Re: declaring with my

2004-09-14 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: Errin Larsen wrote: my @numbers; push @numbers, split while <>; why can't I put that variable declaration in the push function? like this: push my @numbers, split while <>; The original code could be written as: my @numbers; while ( <> ) { push @

Re: declaring with my

2004-09-15 Thread Gunnar Hjalmarsson
Errin Larsen wrote: Gunnar Hjalmarsson wrote: Because the push() statement is in a loop, and my() would empty the variable at each iteration. push my @numbers, split while <>; foreach (sort { $a <=> $b } @numbers) { printf "%20g\n", $_; } This code produces no output ... not even any warnings or

Re: declaring with my

2004-09-15 Thread Gunnar Hjalmarsson
Gunnar Hjalmarsson wrote: Suppose the fact that it doesn't contain the values from the last line proves that my theory is not the whole truth... OTOH, you can study the impact of my() through these examples: my @array; for (1..3) { push @array, $_; print "@array\n"; } Ou