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:
write directory out in alphabetical order?

 



HaveNoBoundary
New User

Sep 21, 2002, 7:49 PM

Post #1 of 6 (945 views)
write directory out in alphabetical order? Can't Post

Hi,

I just want to write a directory out to html in alphabetical order.

Here is what i have:

$dirtoget="/sambar50/music/guitar_pro_files/";
opendir(IMD, $dirtoget) || die("Cannot open directory");
@thefiles= readdir(IMD);
closedir(IMD);



Blah, blah, blah.........


foreach $f (@thefiles)
{
unless ( ($f eq ".") || ($f eq "..") )
{
print("<p align=\"center\"style=\"margin-top: 0\; margin-bottom: 0\"><a href=/music/guitar_pro_files/$f>$f</a><BR></p>");

}
}

this works....the problem is that I want it in alphabetical order.



Any help would be nice!

Please, nothing to complicated!

Thank You in advance!

Chris


davorg
Thaumaturge / Moderator

Sep 22, 2002, 9:36 AM

Post #2 of 6 (944 views)
Re: [HaveNoBoundary] write directory out in alphabetical order? [In reply to] Can't Post

Just use "sort".

Code
open IMD, $dirtoget or die "Can't open directory: $!\n"; 

foreach (sort readdir IMD) {
next if /^\.\.?$/;

print qq(<p align="center" style="margin-top: 0; margin-bottom: 0"><a href="/music/guitar_pro_files/$_">$_</a><br></p>);
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


HaveNoBoundary
New User

Sep 22, 2002, 12:53 PM

Post #3 of 6 (941 views)
Re: [HaveNoBoundary] write directory out in alphabetical order? [In reply to] Can't Post

Thanks!

it worked!

the only prob is that it puts capital letters first then it does lower case.



I will be able to figure that out. *I think*

If not I will be back..

Thanks Mr. Dave Cross!

Peace


(This post was edited by HaveNoBoundary on Sep 22, 2002, 12:54 PM)


davorg
Thaumaturge / Moderator

Sep 22, 2002, 3:25 PM

Post #4 of 6 (936 views)
Re: [HaveNoBoundary] write directory out in alphabetical order? [In reply to] Can't Post


In Reply To
the only prob is that it puts capital letters first then it does lower case.



Code
open IMD, $dirtoget or die "Can't open directory: $!\n";  

foreach (sort { lc $a cmp lc $b } readdir IMD) {
next if /^\.\.?$/;

print qq(<p align="center" style="margin-top: 0; margin-bottom: 0"><a href="/music/guitar_pro_files/$_">$_</a><br></p>);
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


thebitch
User

Sep 23, 2002, 5:49 AM

Post #5 of 6 (931 views)
Re: [HaveNoBoundary] write directory out in alphabetical order? [In reply to] Can't Post

since "sort" is a built-in perl function,
your first reflex should've been `perldoc -f sort' Wink

I say this because it's a reflex you have to develop
(I hope you'll work on it)

SlySlySlySlySlySlySlySlySlySlySlySly


Paul
Enthusiast

Sep 23, 2002, 6:27 AM

Post #6 of 6 (928 views)
Re: [thebitch] write directory out in alphabetical order? [In reply to] Can't Post

Perhaps you'll work on the reflex of not using so many smilies

CoolCoolCoolCoolCoolCoolCool

 
 


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

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