This is Roy Johnson's code, but changed a bit:

#!/usr/bin/perl -w use strict; my @file; while(<DATA>){ chomp; push @file,$_; } &getClients; #---------------------- sub getClients{ my @tuples = map {[split /\s+/, $_]} grep { !/^(?:#|$)/ } @file; foreach(sort {$a->[1] cmp $b->[1]} @tuples){ my ($cltnbr, $cltname, $clNum) = @$_; print "<a href='#' title='$cltnbr' name='$cltname $clNum' oncl +ick='fillText(this);'>$cltname $clNum</a><br />"; print qq|\n|; } } 1; __DATA__ 001 client 1 002 client 2 003 client 3

Which produces:

<a href='#' title='001' name='client 1' onclick='fillText(this);'>clie +nt 1</a><br /> <a href='#' title='002' name='client 2' onclick='fillText(this);'>clie +nt 2</a><br /> <a href='#' title='003' name='client 3' onclick='fillText(this);'>clie +nt 3</a><br />

Now, instead of using a global variable like the above you should pass it into the routine as a reference.

Celebrate Intellectual Diversity


In reply to Re: sorting a file by InfiniteSilence
in thread sorting a file by mooker

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.