Array Initialization

2009-05-12 Thread AndrewMcHorney
Hello I put the strict and warning statements in my perl code. I now need to initialize arrays. What is the best way to initialize an array before the loop where I will basically recreating the array size in the loop? my @array = ? while (more work to do) { @array = split $string; # do

Re: Array Initialization

2009-05-12 Thread Chas. Owens
On Tue, May 12, 2009 at 14:30, AndrewMcHorney wrote: > Hello > > I put the strict and warning statements in my perl code. I now need to > initialize arrays. What is the best way to initialize an array before the > loop where I will basically recreating the array size in the loop? > > my @array = ?

Re: Array Initialization

2009-05-12 Thread John W. Krahn
AndrewMcHorney wrote: Hello Hello, I put the strict and warning statements in my perl code. I now need to initialize arrays. What is the best way to initialize an array before the loop where I will basically recreating the array size in the loop? my @array = ? while (more work to do) {

Re: Array Initialization

2009-05-12 Thread Bryan Harris
[stuff cut out] It is usually best to declare variables in the smallest scope possible so: while (more work to do) { my @array = split $string; # do work on array } Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e. doesn't it re-run the my() fu

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Bryan Harris wrote: [stuff cut out] It is usually best to declare variables in the smallest scope possible so: while (more work to do) { my @array = split $string; # do work on array } Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e. doesn't

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Bryan Harris wrote: Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e. doesn't it re-run the my() function every time through the loop? For some reason I thought that was a no-no. my() happens when the code is compiled so it is *not* re-run every time

Re: Array Initialization

2009-05-12 Thread Gunnar Hjalmarsson
John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $count; $count += 1; print $count; last if $count == 3; } print "\

Re: Array Initialization

2009-05-12 Thread Jenda Krynicky
From: "John W. Krahn" > Bryan Harris wrote: > > > > [stuff cut out] > > > >> It is usually best to declare variables in the smallest scope possible > >> so: > >> > >> while (more work to do) > >> { > >> my @array = split $string; > >> > >> # do work on array > >> } > >> > > > > Doesn't tha

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $count; $count += 1; print $count; last

Re: Array Initialization

2009-05-12 Thread Gunnar Hjalmarsson
John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $count; $count += 1;

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $c

Re: Array Initialization

2009-05-12 Thread Chas. Owens
On Tue, May 12, 2009 at 18:11, John W. Krahn wrote: > Bryan Harris wrote: >> >> [stuff cut out] >> >>> It is usually best to declare variables in the smallest scope possible >>> so: >>> >>> while (more work to do) >>> { >>>  my @array = split $string; >>> >>>  # do work on array >>> } >>> >> >> Do

Re: Array Initialization

2009-05-12 Thread Gunnar Hjalmarsson
John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e '

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run

Re: Array Initialization

2009-05-12 Thread Chas. Owens
On Wed, May 13, 2009 at 01:59, John W. Krahn wrote: snip >> What's your point? > > I am trying to understand what point you are trying to make. snip I believe the point is that declaration is only one of the things my does, so saying that "my() happens when the code is compiled so it is *not* re-

Re: Array Initialization

2009-05-13 Thread Gunnar Hjalmarsson
Chas. Owens wrote: On Wed, May 13, 2009 at 01:59, John W. Krahn wrote: snip What's your point? I am trying to understand what point you are trying to make. snip I believe the point is that declaration is only one of the things my does, so saying that "my() happens when the code is compiled s