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

Re: Failed to create a file

by MidLifeXis (Prior)
on May 06, 2011 at 13:09 UTC ( #903377=note: print w/ replies, xml ) Need Help??


in reply to Failed to create a file

Slightly off topic, but related to coding style of sorts.

open(CFG, "C:\\TEMP\\cfg") || die "Failed to create cfg";

You have included the parens in your call to open, which allows the ... || die ... to work as expected. If you leave off the parens - open CFG, "C:\\TEMP\\cfg" || die "Failed to create cfg";, this will give you the wrong results. Having stubbed my toe on this many times, I have made it my habit to use action or die instead of action || die.

--MidLifeXis


Comment on Re: Failed to create a file
Select or Download Code
Re^2: Failed to create a file
by tchrist (Pilgrim) on May 06, 2011 at 13:29 UTC
    Having stubbed my toe on this many times, I have made it my habit to use action or die instead of action || die.
    An alternative reaction is to always use parens on function calls: some_function(ARGS) || die. The advantage of this strategy is that it improves readability, plus now you donít have to memorize a bunch of confusing and conflicting precedence rules.
      I'm curious, which precedence rules are "conflicting"?

      Also I find the rule "logical operators that are spelled out as words have loose precedence" not too hard to remember.

        That doesnít tell you enough. Itís lower than a comma operator, which makes it unusable in data declarations. I simply gave up on it, and went back to using parens the way God and Dennis intended. Now I never make mistakes. Must safer, and easier to read, too.
Re^2: Failed to create a file
by thezip (Vicar) on May 06, 2011 at 20:50 UTC

    An even alternativer solution to this is to use pjf's great autodie module, which avoids the issue altogether...


    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-07-12 01:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls