Hi there. I'm working with a script that generates a HTML page containing the results of a search. It works basically searching specific field on a pipe delimited file and returns a list of the results found. It's being easy so far.

What I need to do now is to sort this results, so I have two questions:

1) How can I sort this results in alphabetical order?
2) How can I sort this results in numeric order?

The routine that generates the file works on a simple "foreach" statement, like this:
foreach $results (@results){ ($field_1,$field_2,$field_3) = split(/\|/,$results); print<<feach; <tr> <td bgcolor="#C0C0C0" colspan="2"><font face="Verdana, Arial, Helv +etica, sans-serif" size="2">$field_1</font></td> </tr> feach }
The search subroutine goes like this:
sub search_database{ my $search_for = $_[1]; open(DB, $_[0]) or die "Error opening file: $!\n"; while(<DB>){ if($search_field eq "all"){ if(/$search_for/oi){push @results, $_}; } else { ($field_1,$field_2,$field_3)=split(/\|/); if(${$search_field} =~ /$search_for/oi){push @results, $_}; } } close (DB); }
Thanks in advance,

Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper

In reply to Sorting search results in PERL by DaWolf

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.