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 are read in the while
loop.

Thanks,

Chris

#!/usr/bin/perl
use warnings;
use strict;

my @array;

while ( my $line = <DATA> ) {
  chomp $line;
  @array = split(/\s+/, $line,-1);
}

for my $item ( @array ) {
  print $item,"\n";
}

__DATA__
Line1 c 2 3 4 5 C 7 8 9
Line2 1 2 3 4 5 6 7 8 9
Line3 1 2 3 4 5 D 7 8 9
Line4 1 2 3 4 5 aDC6 7 8 9
Line5 1 2 3 4 5 D 7 8 9
Line6 1 2 3 4 5 dcDC 7 8 9

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to