Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: A Tribute To The Monks Of Wisdom

by hossman (Prior)
on Nov 16, 2008 at 03:16 UTC ( #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
Node Status?
node history
Node Type: note [id://723879]
help
Chatterbox?
[Corion]: 1nickt: On Sunday maybe 10cm of snow fell, and the airport closed, and the trains stopped running etc :) It always comes as a surprise that snow falls here during the winter...
[marto]: 1nickt, no snow, just some ice on the roads and the usual idiocy associated with humans and driving in less than ideal conditions
[1nickt]: Corion I am trying to keep an open mind :-) Or at least, go with the flow. marto yes I saw som photos of lorries overturned on country roads, and wondered why they would have been driving fast enough to have that happen!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2017-12-11 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (289 votes). Check out past polls.

    Notices?