Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
So, I hereby dedicate this to every Monk on here, that has ever taken the time to answer a newbie question, in an effort to further a fellow Monk's knowledge.

In the spirit of furthering a fellow Monk's knowledge with constructive criticism...

  • It's a good idea to get into the habbit of writing "close" anytime you write "open" ... perl will close any open filehandles for you when your script ends, but even in really short scripts you could conceivable run out of file handles if you use a lot of them (or if your code gets refactored into a longer running program).
  • if you declare a counter (ie: $i) just for hte purposes of looping over an array, consider foreach instead. This...
    foreach my $filename (@ARGV) { open(MYFILE, $filename) or die("Error: cannot open file '$filename'\n"); print "$filename is readable!\n" if -r MYFILE; print "$filename is writable!\n" if -w MYFILE; print "$filename is executable!\n" if -x MYFILE; print "$filename exists!\n" if -e MYFILE; }
    ...is a little bit easier to read (to me) then what you've got right now, and a little less error prone to off by one errors and/or typos (hint: you're using $ARGV[0] in a place where you probably ment to use $ARGV[$i]
  • the file test operators (-r, -x, etc...) can take a filename as an expression, so you don't *have* to open the files first -- in fact if the file doesn't exist, or isn't readable, you won't be able to open it, so some of those test are redundant. :)

In reply to Re: A Tribute To The Monks Of Wisdom by hossman
in thread A Tribute To The Monks Of Wisdom by koolgirl

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 browsing the Monastery: (1)
As of 2024-04-25 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found