Thomas H. George wrote:
How can I retrieve data loaded into an array within a foreach block? The array is defined outside the foreach block and is not the indexing array of the foreach loop.
I was about to ask the same question as Alex did. A few other remarks:
my @lines = (); my @line = ();
It seems like there is no need to define those variables outside the loop.
my @lastnames = (); loaded into @lines a file
Why? If there is no particular reason to do so, the better practice is to read the file line by line.
Please consider this code: my $file = 'data.txt'; open my $fh, '<', $file or die "Opening $file failed: $!"; my @lastnames; while ( <$fh> ) { my @line = split /\t/; chomp @line; # if the record has no further elements push @lastnames, $line[1]; } -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/