|go ahead... be a heretic|
Re^4: Including filesby Athanasius (Chancellor)
|on Aug 30, 2014 at 04:04 UTC||Need Help??|
Sorry, I think you’re reading Juerd’s tutorial back-to-front.
So now tell me again why I'm not supposed to just use require to read in a library of functions?
Well, it’s usually better to say:
because that’s a convenient shorthand for:
which is likely to be what you want (see use.) But whether it’s use or require, that’s exactly what you are supposed to use to “read in a library of functions”. Juerd isn’t telling you not to use require, he’s telling you that neither require nor do will give you the equivalent of C’s #include.
In fact, in C I have to add macro definitions and ifs to get include files to include only once.
Exactly! But Juerd’s point is that some programmers want to use #include to include the same code in multiple places, and that won’t work with require. It will work with do, except that “code evaluated with do FILENAME cannot see lexicals in the enclosing scope” — do. So if you have a file “foo.pl”:
which you then try to “include” in another file using do:
the result is probably not what you wanted:
Hope that helps,