I searched the database and found a lot of information about sorting but unfortunately I could not quite wrap my brain around what I was seeing so decided to post

I have a text file that has names of books, number of pages, etc. The information is separated by colons (:). I could manually create sorted lists but what's the fun in that? I have not made any attempts that I can show, but I will list the code as it is, which deals with the formatted data being used in HTML output

my $file = 'books/bookLIST.txt'; open my $info, $file or die "Could not open $file: $!"; while(my $line = <$info>) { foreach ($line) { chop; @vlinks = split(/:/,$_) ; print "<tr><td><a href=\"bookDETAIL.cgi?book=$vlinks[1]\">$vli +nks[0]</a></td><td>$vlinks[2]</td><td>$vlinks[3]</a></td></tr>" } } # each line in the text file is as follows: # Title of Book:title_of_book:<number of pages>:Author's Name

I would like to be able to sort by vlinks[0], vlinks[2] or vlinks[3] but cannot figure where to sort and how. Any help would be appreciated.


In reply to Sorting Text File for HTML Output by michael.kitchen

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.