Think it through. What exactly are you sorting on? If you want to sort on the first value, then the second, then the third, and sort asciibetically, then just do a sort on @DB. However, if you want to sort then, you have to split each line up into its component parts. Something like the following will help:
my @records = sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] || $a->[2] cmp $b->[2] || $a->[3] <=> $b->[3] } map { [ split '#', $_ ] } map { chomp; $_ } @DB;

You have to read that code from bottom to top.

  1. You have all the lines in @DB
  2. Take each line and perform a chomp on it. Since chomp() returns the character(s) removed (if any), you need to explicitly return $_
  3. Create an array reference containing the values in the record (using split(), just like you were)
  4. Sort those records based on the elements of the record. <=> is a numeric sort. cmp is an asciibetical sort.

When it's all done, @records will be an array containing array references. If you need more explanation, please ask.

------
We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose


In reply to Re: Sort Problem by dragonchild
in thread Sort Problem by Anonymous Monk

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.