in reply to 'Required' config file produces error if last entry sets variable to zero?

Consider using do 'config.pl'; instead. That way you don't need to return a true value.
  • Comment on Re: 'Required' config file produces error if last entry sets variable to zero?
  • Download Code

Replies are listed 'Best First'.
Re^2: 'Required' config file produces error if last entry sets variable to zero?
by AK108 (Friar) on Jun 11, 2006 at 20:16 UTC
    There's a few pitfalls with do:
    • do doesn't do the error checking that require does regardling the loading of a file (you need to check the return value)
    • do forces a load/execute of the file, even if it's already loaded (require doesn't load/execute files more than once)

    See do in the documentation (do EXPR is what you're interested in).

      Whether those pitfalls are a good or a bad thing probably depends on the requirements. For example, if one would like to support config reloading the second pitfall would actually be a good thing.

      I guess the issue is more a matter of style than any technical reason. It might be best to choose whatever one feels comfortable with.

      It may even depend on how you view the configuration: If the configuration feels like part of the program, require or use might be better because it's heaviliy associated with module loading. That way, the final 1; in the configuration won't feel awkward, too. If the configuration is more external, and Perl is mostly used for syntactic convenience, I'd prefer do.