Hey thanks again for the reply. I think that I may not be explaining myself in the best way, but here is the code that I have currently.
my @lines = read_file('/tmp/test.txt'); chomp(@lines); my $sql = q|select * from table_name where srcaddr = ? or dstaddr = ?| +; my $sth = $dbh->prepare($sql) or die "Can't prepare SQL statement: $DB +I::errstr\n"; foreach my $line (@lines) { $sth->execute($line, $line) or die "Can't execute SQL statemen +t: $DBI::errstr\n"; my @all_rows; while ( my $ref = $sth->fetchrow_arrayref()) { push(@all_rows, $ref); } my @sorted = map {$_->[0]} sort {$a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] || $a->[4] <=> $b->[4]} map { [$_, split(/\./, (split /\s+/, $_)[1])]} @all_rows; print "$_\n" for @sorted; }
The problem is that whenever I run the code I get the following shown below. I am guessing this is because I am using the array @all_rows which it doesn't know how to handle? I am saving the output/results from the SQL query to an array called @all_rows, now what I want to do is sort the data in column 2 in that array. What is the proper way to work/sort the data in the array @all_rows which contains all the sql results. Thanks again for the help..
ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80) ARRAY(0x96b0d80)
FYI if I print the @all_rows array using a foreach loop I get the proper results
foreach my $row_ref (@all_rows) { print "@{$row_ref}\n"; }

In reply to Re^4: Saving sql results to an array all rows? by learningperl01
in thread Saving sql results to an array all rows? by learningperl01

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.