Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Re: Code factory

by duct_tape (Hermit)
on Jul 08, 2003 at 14:36 UTC ( #272302=note: print w/replies, xml ) Need Help??


in reply to Re^2: Code factory
in thread Code factory

Instead of doing this:
push @{$results}, { map { $_, $row->{$_} } keys %{$row} };
Wouldn't it be better/faster to just do this:
push @{$results}, $row;
You already have a hash reference, why recreate it?

Replies are listed 'Best First'.
Re: Code factory
by tadman (Prior) on Jul 08, 2003 at 19:01 UTC
    If I recall correctly, DBI recycles the hash reference with each iteration. What you end up with is an ARRAY of exactly the same HASH data. You should duplicate it, as was done with that first bit of code, or better yet:
    push(@$results, { %$row });
      No, it does a new hashref every time. At least, this works for me:
      my @result; while (my $row = $sth->fetchrow_hashref()) { push @result, $row; }

      This is a late response since I tend to not pay attention too often.

      DBI recycles arrayref's, but not hashref's. It may be good to make a copy of the hashref just in case that changes in the future though....

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://272302]
help
Chatterbox?
Eily notes also
[hippo]: So if you don't drink as much milk and not as often you are said to drink less milk on fewer days. Confusing, eh?
[Eily]: same as many/much, few/little
[Discipulus]: so my 'less' usage sounded not so correct? 'fewer' was more appropriate? i take a note too

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-01-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (242 votes). Check out past polls.

    Notices?