Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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

In reply to Re: help please by Revelation
in thread help please by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-18 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found