You need to change @INC in a BEGIN block in order for it to affect use commands, since they take effect at BEGIN-time. But Octavian is using require 'timelocal.pl';, which takes place at run time (Octavian: you seem to be using some old code with some old syntax; are you sure there isn't something newer that might be easier to use?). So Beatnik's change of @INC at run time is enough, as long as it takes place before the require.
Yet More Ways of setting @INC before your script starts running (and thus in time to affect both use and require):
- Add them to your shebang line:
#!/path/to/perl -w -I/opt/perl5/lib/5.6.1
- use lib:
use lib qw(/opt/perl5/lib/5.6.1);
(this also works in a module, of course)
Use either, not both!
Either is preferable to manipulating @INC directly: it's clearer, and you get nicer behaviour simpler (e.g. beatnik's and Azatoth's code above adds the new directory as the last directory to be searched; you'd usually want to search it first). | [reply] [d/l] [select] |