Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Pushing Array ref to array

by hardburn (Abbot)
on Feb 01, 2012 at 16:15 UTC ( #951258=note: print w/ replies, xml ) Need Help??


in reply to Pushing Array ref to array

The problem is that each entry in @result is a reference to @row, but because @row is declared at the top of the code, you change the contents of @row each time through. Instead, you need to create a new variable each time through the loop.

This is quite easy:

while (my @row = $sth->fetchrow_array()) { ... }

And you should be able to delete the my @row; line at the top of the code.

Here's something that may help you understand better: Lexical scoping like a fox.


"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.


Comment on Re: Pushing Array ref to array
Select or Download Code
Re^2: Pushing Array ref to array
by packetstormer (Monk) on Feb 01, 2012 at 16:42 UTC
    Thanks to you both. That worked but I really should have known better!
    Thanks again.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-08-22 03:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (146 votes), past polls