Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: A Tribute To The Monks Of Wisdom

by hossman (Prior)
on Nov 16, 2008 at 03:16 UTC ( [id://723879]=note: print w/replies, xml ) Need Help??


in reply to A Tribute To The Monks Of Wisdom

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. :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found