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

It looks like you are confusing text read in from a file with text that's part of your program's code. The latter is interpreted by the perl compiler; the former just gets shoved into the variable.

There's More Than One Way To Do It. If you really trust your input data, you could stick it inside an eval().

What you probably want to do, though, is read up on split(). From the example you provided, you'll probably want something a bit more sophisticated. Try searching for 'CSV' at CPAN

  • Comment on Re: How can I read a line of text from a file into an array?

Replies are listed 'Best First'.
Re: Re: How can I read a line of text from a file into an array?
by suaveant (Parson) on Jul 16, 2001 at 22:29 UTC
    Yeah, since you are using quoted text with contained commas I would certainly look into the CSV modules on CPAN...

    or get rid of the quotes and as long as your keys and values don't contain any commas you could do...

    $line = 'key1,value1,key2,value2'; my %foo = split ',', $line; print $foo{key2}; #prints the value associated with key2, i.e. value2

                    - Ant