Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: help please

by Revelation (Deacon)
on Mar 26, 2002 at 01:58 UTC ( [id://154300]=note: print w/replies, xml ) Need Help??


in reply to help please

The readdir() function will return ., and .. as directories, in addition to the other directories on under that directory.. I'm not sure you want to use that, as you may end up coding a reverse recursive function, until you have done this to every directory you have access to. To fix this you may wish to do something as simple as greping to check if your result is actually there.

Also: Instead of -d $dirname, it may be simpler to just die, if the directory can't be opened?
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
Or you can write a function to nicely die, and output the reason for it to the user. Just remember to exit;, with that function.

so: instead of
if ( -d $dirname) { print "$dirname is a directory thankyou \n"; opendir(DIR, $dirname); @filenames = readdir(DIR); blah blah blah blah blah
You Could Use:
opendir(DIR, $dirname) || die "can't opendir $dirname: $!"; my @directory = readdir(DIR); my @filenames = grep { -f "$dirname/$_" } @directory; # Either use th +e array @directory, or rewinddir(DIR) here, and grep readdir(DIR) twi +ce. my @directories = grep {-d "$some_dir/$_" && !/^\.$/ && !/^\..$/} @di +rectory; closedir DIR;

And you'd have a list of everything in the directory, without . and .., and with diff arrays for directories and files. In fact, since you're only editing certain types of files, you could change the first grep to suit your needs, with a regex, or you could add a few greps for the differant types of files, which would let you change shtml files to html files rather easily. If you want to have only two greps, then use && regex.

It's also my opinion that your teacher will not be very happy if you use a ton of perl modules, as the point of this excersize seems to be to test your knowledge of perl, not the writer of a perl modules' knowledge. Using a perl module is like using somebody else code, which is alright in the GNU/perl world, but is not alright in school. I would advise hard coding much of it, and adding comments to show your teacher that you know perl modules.
Gyan Kapur
gyan.kapur@rhhllp.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://154300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2024-04-19 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found