in reply to How can I read a line of text from a file into an array?

Hello,

Try using some of the code below. A note of caution is that using map will create a 2d array. If you only have one line in the file they will all apear in the 0th element of the first dimension of the array. I hope this helps.

Donesh

Code:

sub getdata { my $filename = "<" . shift; open (HANDLE,$filename) or die "Cant Open $filename: $!"; my @final = map{chomp; [split/,/]} <HANDLE>; close HANDLE; return (@final); }

Replies are listed 'Best First'.
Re: Re: How can I read a line of text from a file into an array?
by dvergin (Monsignor) on Jul 16, 2001 at 22:41 UTC
    This code makes unnecessary use of an anonymous array making handling of the returned values more involved than necessary. It also retains the single-quotes in the data resulting in this set of values:
    'key1 value1' 'key2 value2' 'key3 value3' 'key4 value4'