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!

#!/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 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!

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.