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

Re^4: eval "require $class" seems wrong (--!$@)

by ikegami (Patriarch)
on Aug 22, 2007 at 19:14 UTC ( [id://634485]=note: print w/replies, xml ) Need Help??


in reply to Re^3: eval "require $class" seems wrong (--!$@)
in thread eval "require $class" seems wrong

The 1 is useless since require always returns true. (If it encounters no error, it returns what the module returns. If the module returns false, it encountered an error. If it encounters an error, it throws an exception.)

Replies are listed 'Best First'.
Re^5: eval "require $class" seems wrong (1)
by tye (Sage) on Aug 22, 2007 at 19:23 UTC

    Yes, and the space is equally "useless" because require"$file.pm" works just fine. That doesn't mean I'm going to drop either of them.

    The "; 1" is part of the best practice. It may not change the effect of this particular code, but it means I don't have to worry about whether the preceeding code might return a false value rather than dieing. It also tells the reader that I'm testing whether eval succeeded not whether the eval'd code returned a true value (which also makes it clearer why I'm using eval at all).

    - tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-28 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found