On 05/07/2012 04:47 PM, timothy adigun wrote:
sub get_data {
my ($file) = @_;
my $arr_ref = [];
open my $fh, '<', $file or die "can't open this file: $!";
while (<$fh>) {
chomp;
push @$arr_ref, $_;
}
close $fh or die "can't close file:$!";
return $arr_ref;
}
why so much code to slurp in an array of lines? this does the while loop:
chomp( my @lines = <$fh> ) ;
return \@lines ;
no need for the $arr_ref line or even the close line as the handle will
be closed upon leaving scope.
or better yet use File::Slurp in list mode and it has a chomp option now.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/