Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming
View Poll Results:
0%
Voters: 0. You may not vote on this poll


Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 13th, 2001, 08:51 PM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Sorting Dir above files

Using apache 1.3x , win98 beta 3001, perl 5.6.x

Required : trying to sort alphabetically Dirs = first , Files =second.


Code Fragment :

$bob="c:\\windows";

opendir(SEARCH,"$bob") || die " Cannot open $bob : $! ";

@all=sort{lc $a cmp lc $b} grep(!/^\.+$/,readdir(DIR));

closedir(SEARCH);

foreach $name(@all){

print " $names\n";

}


Trouble :

This code works but my brain is looking for dir's above files.

I suppose I am looking for a new sort fragment or ???


__________________
Thanks

Foot in Mouth ver 1.2.5 Onion

Reply With Quote
  #2  
Old June 13th, 2001, 09:05 PM
dkode dkode is offline
PHP/PERL/.NET Coder
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Daytona Beach, Florida
Posts: 36 dkode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 sec
Reputation Power: 8
Send a message via AIM to dkode
I'm not sure exactly what your're trying to do?

Are you trying to grab all files and dirs in a specific directory and then sort them into dirs(alphabetically) and then files(alphabetically)?

If so, I beleive you can acomplish what you are trying to do much easier by using glob.

perldoc glob
should give you what you need to use it. It's very useful and i've used it many times before for various different projects.

Hope this helps!

DKode
__________________
"Mankind cannot define memory, yet it defines mankind"

Reply With Quote
  #3  
Old June 13th, 2001, 09:18 PM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Yes exactly dir first .. files second

I am thinking:

Result as printed as :

aaa [dir]
bbb [dir]
.... [dir]
zzz [dir]

aaa.txt [file]
bbb.txt [file]
.... .txt [file]
zzz.txt [file]

As per the grooovy graphic's of sorting


Reply With Quote
  #4  
Old June 13th, 2001, 10:43 PM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Sample =>While my local computer ON

Try:

Test Computer [ not online at any moment ]

http://bkgt21oty8yk.bc.hsia.telus.net/cgi-bin/dir.pl

but as you will see dir's and files are mixed.

Note : I turn off this computer and reboot often to linux / NT 2000k so try later.

Reply With Quote
  #5  
Old June 14th, 2001, 02:15 AM
dkode dkode is offline
PHP/PERL/.NET Coder
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Daytona Beach, Florida
Posts: 36 dkode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 sec
Reputation Power: 8
Send a message via AIM to dkode
With glob you can grab all the dir names and drop them into one array and then grab all the filenames and drop them into another one.

You would then do:

@sorted_dirs = sort(lc($a) cmp lc($b)) @unsorted_dirs;
@sorted_files = sort(lc($a) cmp lc($b)) @unsorted_files;

print @sorted_dirs;
print @sorted_files;

Hope that helps to some effect. I have a script with examples of glob but I can't seem to find it right now, try checking out perldoc.com.

Reply With Quote
  #6  
Old June 14th, 2001, 12:00 PM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Yep Got it to work

I realised after some sleep that I could go back
to the array and do as you show above split them into 2 array's
to use.


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Sorting Dir above files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT