Re: lexical scope

2012-06-05 Thread John W. Krahn
Chris Stinemetz wrote: Why does this short program only seem to capture the last line of input in the @array, but when I put the for loop inside the while loop all lines of input are available in @array. I thought by declaring the @array outside the while loop would make all of its contents avai

Re: lexical scope

2012-06-05 Thread Shawn H Corey
On 12-06-05 08:31 PM, Steve Bertrand wrote: On 05/06/2012 3:49 PM, Shawn H Corey wrote: On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line = ) { chomp $line; push (@array = split(/\s+/, $line,-1));

Re: lexical scope

2012-06-05 Thread Steve Bertrand
On 05/06/2012 6:31 PM, Steve Bertrand wrote: On 05/06/2012 3:49 PM, Shawn H Corey wrote: On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line = ) { chomp $line; push (@array = split(/\s+/, $line,-1));

Re: lexical scope

2012-06-05 Thread Steve Bertrand
On 05/06/2012 3:49 PM, Shawn H Corey wrote: On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line = ) { chomp $line; push (@array = split(/\s+/, $line,-1)); push @array, [ split /\s+/, $line, -1 ]; I

Re: lexical scope

2012-06-05 Thread Shawn H Corey
On 12-06-05 05:43 PM, Bill Stephenson wrote: Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line = ) { chomp $line; push (@array = split(/\s+/, $line,-1)); push @array, [ split /\s+/, $line, -1 ]; } for my $item ( @array ) { print $i

Re: lexical scope

2012-06-05 Thread Bill Stephenson
Maybe this is what you need? #!/usr/bin/perl use warnings; use strict; my @array; while ( my $line = ) { chomp $line; push (@array = split(/\s+/, $line,-1)); } for my $item ( @array ) { print $item,"\n"; } Kindest Regards, Bill Stephenson On Jun 5, 2012, at 4:15 PM, Chris Stinemetz wr

Re: lexical scope

2012-06-05 Thread Robert Wohlfarth
On Tue, Jun 5, 2012 at 4:15 PM, Chris Stinemetz wrote: > Why does this short program only seem to capture the last line of > input in the @array, but when I put the for loop inside the while loop > all lines of input are available in @array. > > while ( my $line = ) { > chomp $line; > @array

lexical scope

2012-06-05 Thread Chris Stinemetz
Why does this short program only seem to capture the last line of input in the @array, but when I put the for loop inside the while loop all lines of input are available in @array. I thought by declaring the @array outside the while loop would make all of its contents available once all the lines