Perl-Sensitive Sunglasses | |
PerlMonks |
Re^3: eval "require $class" seems wrong (--!$@)by tye (Sage) |
on Aug 22, 2007 at 19:05 UTC ( [id://634479]=note: print w/replies, xml ) | Need Help?? |
If you change "::" to "/" and append ".pm", then you don't need a string eval, you can just do require $class. I wouldn't even do eval { require $class } (non-string eval) unless I was wanting to work around the module not being found. But if you do want to eval, then the best choice is:
But I don't find the argument against string eval compelling enough to have much of a strong preference between that and the below string eval unless there is risk that $class might contain mischevious data:
If you don't want to work-around a failure (and trust $class), then the choices are:
and
And I'd never use UNIVERSAL::require, since I consider poluting such a very global namespace to be way too much sin for the sake of saving one line of code. - tye
In Section
Seekers of Perl Wisdom
|
|