Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: hash_reference from file

by jwkrahn (Monsignor)
on Sep 29, 2011 at 11:33 UTC ( #928528=note: print w/ replies, xml ) Need Help??


in reply to Re: hash_reference from file
in thread hash_reference from file

while (<DATA>) { my @line = split; my %hash; @hash{+KEYS} = @line; push @array, {%hash}; }

Why create a hash in the lexical scope of the while loop and then make a copy of that hash instead of just using a reference to that lexically scoped hash?

while (<DATA>) { my %hash; @hash{ +KEYS } = split; push @array, \%hash; }


Comment on Re^2: hash_reference from file
Select or Download Code
Replies are listed 'Best First'.
Re^3: hash_reference from file
by choroba (Canon) on Sep 29, 2011 at 13:22 UTC
    You are absolutely right. I was typing too fast :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2015-07-30 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls