http://www.perlmonks.org?node_id=444575


in reply to Re: Interview Prepration
in thread Interview Prepration

3. Explain the difference between use and require.

"use" is at compile time, "require" is at run-time? It's weird how you code and code and only when somebody asks you something you start having questions about it :

use also calls import(). From use:

Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to

BEGIN { require Module; import Module LIST; }

-

8. What is the difference between for & foreach, exec & system?

for & foreach are now an alias to each other (Ok, one of them is implemented, but they're actually the same thing). As for exec & system, I don't use them much, so I'd have to check on documentation (and don't forget backticks, too)

for can be used as an alias for foreach, and visa-versa. But please, please don't use foreach with a C style for loop:

foreach ( loop_init(); exit_test(); increment() ) { ... }

As for exec and system, one of 'em forks, one doesn't. I always forgot which one is which, and look them up, too. (exec never returns, while system does) and sometimes, I just open a pipeline.