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:
Omitting DIR filenames with filespecs

 



S_Shrum
User

Mar 20, 2001, 2:13 PM

Post #1 of 2 (275 views)
Omitting DIR filenames with filespecs Can't Post

I have a directory that contains photos and thumbnails structured like:

photo1.jpg
~photo1.jpg

...where the ~filename is the thumbnail.

I want to do a directory listing minus all filenames that start with "~".

Sean Shrum
sean@shrum.net
www.shrum.net


japhy
Enthusiast

Mar 21, 2001, 7:08 AM

Post #2 of 2 (270 views)
Re: Omitting DIR filenames with filespecs [In reply to] Can't Post

This is an excellent change to learn how to use regular expressions:


Code
opendir DIR, $path; 
@files = grep !/^~/, readdir DIR;
closedir DIR;

That regex says "match a ~ as the first character" and the ! in front of it is the logical NOT operator which flips the value. Thus, if a file DOES have a leading tilde, the regex returns true, but the NOT value of that is false, and therefore, it doesn't pass through.


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

 
 


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

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