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)