On Jun 19, mark crowe (JIC) said:

>I wonder if anyone can help me with a question based more on curosity than a
>desperate need to know. Say I have a data file with one key/value pair on
>each line, which I want to read into a hash. I've been doing it in one of
>two ways:
>
>  while (<>) {
>    ($key, $value) = split;
>    $hash{$key} = $value;
>  }
>
>or 
>
>  push @array, split while <>;
>  %hash = @array;

It's better for memory if you do it one-at-a-time, but if you'd really
like a one-liner, I'd use:

  %hash = map split, <>;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to