Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Setting a hash element to a anoymous hash

by Belgarion (Chaplain)
on May 18, 2004 at 21:00 UTC ( #354438=note: print w/replies, xml ) Need Help??

in reply to Setting a hash element to a anoymous hash

I believe when the following code executes:

if ( $i != 0 ) { $time{$previous} = { 'end_date' => $date, 'end_time' => $time }; }

it's overwriting the previously stored hashref. In other words, you're not appending the new information, but replacing the old. You could use something like this:

if ( $i != 0 ) { $time{$previous} = { %{$time{$previous}}, 'end_date' => $date, 'end_time' => $time }; }

to add the new information to the end. This will dereference the previous hashref before adding the new code.

Update Fixed the code to use an assignment. Also, see kvale's comment below.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2023-03-27 16:48 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (65 votes). Check out past polls.