Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Preserving hash structure after subroutine call

by suaveant (Parson)
on May 13, 2003 at 21:08 UTC ( [id://257899]=note: print w/replies, xml ) Need Help??


in reply to Preserving hash structure after subroutine call

It may be that the reference to the fetchrow_hashref is somehow losing scope outside the subroutine. I tried by faking your data in and it worked fine.

as for sugestions, I would just do

$href->{$ct} = $tmp_href; #rather than $results{$ct} = $tmp_href;
that way you don't need to waste time and memory on a copy of the hash

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re: Re: Preserving hash structure after subroutine call
by Anonymous Monk on May 13, 2003 at 21:31 UTC
    Yes. I had used that variant earlier without the intermediate hash but with the same results. I used the intermediate hoping that the references would resolve to actual data during the assignment:
    %{ $href } = %results;

    In my example I tried using Storable's dclone() which I thought replace the references with the real data, but apparently not. I agree that it has something to do with scoping, I'm just not sure how to solve it.

      well... try
      while(my $row = $sth->fetchrow_hashref() && my %row = %$row)
      or something similar. Copy the row hash.

                      - Ant
                      - Some of my best work - (1 2 3)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-16 16:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found