On 03/04/2015 11:15 PM, Brandon McCaig wrote:
I think that generally you should be using `use' unless you have a specific need to use require directly. `use' will call require() under the surface when needed so to you it's basically the same, but it has added benefits that make sense generally. If you want the action to happen at run-time then require() may be more appropriate, but those cases should be rare. Similarly, require is sort of like a wrapper over `do FILENAME' so there may also be cases where you'd want to use `do' instead, but most of the time use is more appropriate, and less often require is more appropriate. For the detailed explanation take the time to read through the following: perldoc perlmod (search for BEGIN) perldoc -f use perldoc -f require perldoc -f do Then use `use' until you know you need something else. :) Regards,
what you said is good. i just want to emphasize about compile vs run time in perl. perl being a dynamic language doesn't have the classic compile to machine code and then run phases of langs like c and c++. a BEGIN block runs immediately after it is compiled, before any regular code in the file. as said, use is like require in a BEGIN block (plus the importing). and the other direction is eval STRING which compiles and runs code at run time. and if you call eval STRING in a BEGIN block you are compiling code (and running it) at run time of the code of the BEGIN block. it can be tricky to follow that but it all makes sense. any block of perl has to be compiled. and then it gets run. BEGIN and eval STRING allow you to control when those phases happen. and there are powerful uses for that but rarely do beginners need them. eval STRING is so dangerous that i always say you shouldn't use it until you know when not to use it. same for symrefs.
uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/