CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Sort Question

 



liftn
Deleted

Nov 16, 2000, 12:26 PM

Post #1 of 4 (276 views)
Sort Question Can't Post

If I have the following routine, how can I sort the input fields alphabetically?

# Format User Input in Description


@list = split (/\|/, $desc);

$desc = shift (@list);
$desc =~ s/\[/</g;
$desc =~ s/\]/>/g;
$desc = $fontdesc_s . $desc . $fontdesc_e;

foreach $li (@list) {
($lk, $lv) = split (/::/, $li);

if ($makelist) {
$desc = $desc . "$font_key_s<li>$lk: $font_key_e$font_val_s$lv$font_val_e";
} else {
$desc = $desc . " - $font_key_s$lk: $font_key_e$font_val_s$lv$font_val_e";
}

}

push (@tmpfile, "<td>$desc </td> \n");


japhy
Enthusiast

Nov 16, 2000, 12:30 PM

Post #2 of 4 (276 views)
Re: Sort Question [In reply to] Can't Post

Um, did sort() not work for you?

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


for (sort @fields) { print "$_\n" }
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



liftn
Deleted

Nov 16, 2000, 12:48 PM

Post #3 of 4 (276 views)
Re: Sort Question [In reply to] Can't Post

I'm not quite sure where to put it in the function


sleuth
Enthusiast

Nov 17, 2000, 10:15 AM

Post #4 of 4 (276 views)
Re: Sort Question [In reply to] Can't Post

 
Change

foreach $li (@list) {

To

foreach $li sort(@list) {

:)

Sleuth

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives