Hello Monks
I am having a brain melt at the moment and I can't seem to figure out why this isn't working.
The code is simple, it connects to a DB and queries it return the results to an array called @row. If I print this array within the loop each results is outputted as expected. However, if I tried and push each iteration of the array into another array the results are unexpected. The code is below -> be nice!
I am expecting to end up with a list called @result which will contain array references for each iteration of the @row array in the loop. That isn't happening!#!/usr/bin/perl use strict; use DBI; use Data::Dumper; my @result; my @row; my $dsn = 'DBI:Sybase:server=host.db.local'; my $dbh = DBI->connect($dsn, "sa", 'password'); die "unable to connect to server $DBI::errstr" unless $dbh; $dbh->do("use mydatabasename"); my $query = "select c.uniq,c.ticketid,c.tickettitle,c.assignedto1,c.st +atus,c.area,c.a_email1, c.email from csCustIncident c, csIncident_lineitems l where c.uniq = l.incident_uniq and c.compdate > (select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)) and c.ticketid not in (select ticketid from email_ticket) "; my $sth = $dbh->prepare ($query) or die "prepare failed\n"; $sth->execute( ) or die "unable to execute query $query error $DBI:: +errstr"; while (@row = $sth->fetchrow_array()) { # This line prints the list @row to screen fine print "@row\n"; # But if I try and push the @row list into the @result list I +get strange results push (@result,\@row); }
I'm guessing the @result arary is being reset on each iteration but I can't figure out how to fill it and have a full list at the end?
In reply to Pushing Array ref to array by packetstormer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |