Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: The 'eval "require $module; 1"' idiom (intended)

by davido (Archbishop)
on Apr 19, 2014 at 20:03 UTC ( #1082914=note: print w/ replies, xml ) Need Help??


in reply to Re^2: The 'eval "require $module; 1"' idiom (intended)
in thread The 'eval "require $module; 1"' idiom

++

...which is why, as an idiom, it's wise to disconnect the success flag from the return value of the thing_that_may_fail(). I'm glad I'm not alone in seeing merit in the clarity that comes from decoupling the thing that may fail from the idiom that tests it.

The point to "eval "possible_failure(); 1"" is that we're not concerned with possible_failure()'s return value, we're concerned whether or not it threw an exception. We shouldn't have to look up and infer what its return value will be, we should simply test whether it threw an exception or not. That's where 1;" or warn "Woops!"; comes in.


Dave


Comment on Re^3: The 'eval "require $module; 1"' idiom (intended)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (11)
As of 2014-12-27 19:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls