Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: map to hash of arrays

by dpuu (Chaplain)
on Jul 22, 2004 at 21:13 UTC ( #376719=note: print w/ replies, xml ) Need Help??

in reply to map to hash of arrays

It is obviously possible, but it would not be "nifty". In fact, I think it'd be worse solution than just using a C<for> loop in the first place. You just have to build a temportary hash off to the side. But if you're going to build a tmp hash, then you might as well just build the real one.

Opinions my own; statements of fact may be in error.

Comment on Re: map to hash of arrays
Replies are listed 'Best First'.
Re^2: map to hash of arrays
by emilford (Friar) on Jul 26, 2004 at 14:18 UTC
    That's my issue. I want to build the real hash of arrays without the need of a temporary one. I'm just not sure how to go about doing that.
      Use a while loop, not a map:
      my %hash; my $key; while (<>) { /\S+ : (\S+)/ or die "unexpected line format: $_"; my $value = $1; if (defined $key) { push @{ $hash{$key} }, $value; undef $key; else { $key = $value; } }
      Opinions my own; statements of fact may be in error.
        Why would I want to use this over ccn's solution? Is it a matter of efficiency?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://376719]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2015-11-25 15:59 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (682 votes), past polls