hi all
I have a plain text file with a couple of hundred lines in it like so:
001 client 1
002 client 2
003 client 3
etc etc
My problem is that I need to loop through this file and print out the clients in alphabetical order - the thing is that each client must retain its order number, the reason being is that each client is a link, and pressing on this link prints out the client and its number to 2 input text boxes. Printing them out is no problem (using javascript)
but I cant get perl to sort the client alphabetically while keeping the correct number.
I've written 2 subs - the first works fine as its the numbers that are printed but the second one has stumped me - I tried to use arrays, hashes etc but no joy
#this one works
sub getNumbers{
foreach(@file){
next if m/(^#|^$)/;
my ($cltnbr, $cltname) = split (' ', $_);
print "<span class='spacer'><a href='#' title='$cltnbr' name='
+$cltname' onclick='fillText(this);'>$cltnbr</a></span>";
}
}
#help!
sub getClients{
foreach(@file){
next if m/(^#|^$)/;
my ($cltnbr, $cltname) = split (' ', $_);
print "<a href='#' title='$cltnbr' name='$cltname' onclick='fi
+llText(this);'>$cltname</a><br />";
}
}
any help appreciated!
Mike
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.