I have a simple Perl script that prints out @INC
as the following:
#!/usr/bin/perl
print $_, "\n" for @INC;
I execute the script in 2 different ways with ./test.pl
and perl test.pl
, the output as the following:
[neevek@~/bin]$ ./test.pl
/Library/Perl/5.12/darwin-thread-multi-2level
/Library/Perl/5.12
/Network/Library/Perl/5.12/darwin-thread-multi-2level
/Network/Library/Perl/5.12
/Library/Perl/Updates/5.12.3
/System/Library/Perl/5.12/darwin-thread-multi-2level
/System/Library/Perl/5.12
/System/Library/Perl/Extras/5.12/darwin-thread-multi-2level
/System/Library/Perl/Extras/5.12
.
[neevek@~/bin]$ perl test.pl
/opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level
/opt/local/lib/perl5/site_perl/5.12.3
/opt/local/lib/perl5/vendor_perl/5.12.3/darwin-multi-2level
/opt/local/lib/perl5/vendor_perl/5.12.3
/opt/local/lib/perl5/5.12.3/darwin-multi-2level
/opt/local/lib/perl5/5.12.3
/opt/local/lib/perl5/site_perl
/opt/local/lib/perl5/vendor_perl
.
My question is: what's behind the scenes for executing a perl script with ./script.pl
and perl script.pl
? what causes the script to output different @INC
?
The script is executing perl
from /usr/bin
through the shebang line, but launching the script from the command line uses a different perl
binary, from /opt/somewhere
(see which perl
for the path). You can use #!/usr/bin/env perl
to make both options behave the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With