Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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; }

Replies are listed 'Best First'.
Re^3: hash_reference from file
by choroba (Chancellor) 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?
[LanX]: what is the intention of your question?
[LanX]: why do you need to see the nodelet without votes left???
[marinersk]: LanX, the problem is that the lack of interface visual stability is disconcerting to me. The Nodelet appearing and disappearing is distracting, and despite over a decade, still troubles me. It jangles me.
[LanX]: I see
[marinersk]: I appear to be unusually dependent on spacial stability. I have had trouble from someone moving an object a mere four inches to the left.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-05-29 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?