Can I write a Perl program where my first line is not #!/path/
?
Thank you.
Can I write a Perl program where my first line is not #!/path/
?
Thank you.
The shebang (#!
)is only necessary if you want to invoke the script directly at a shell prompt, e.g. ./yourscript
. You can always do perl yourscript
and skip the shebang.
If your concern is hard-coding a constant path (e.g. #!/usr/bin/perl as opposed to #!/usr/local/bin/perl), then use:
#!/usr/bin/env perl
This allows the Perl interpreter to be sought in your PATH, making your scripts a bit more portable (Windows aside).
Yes, from perldoc perlrun
(under the -S
switch):
#!/bin/sh
eval 'exec /usr/bin/perl -wS $0 ${1+"$@"}'
if $running_under_some_shell;
See that documentation for the complete story.
If you do that then you'll need to invoke Perl explicitly. If that line is there, then the system knows that it is a Perl script so when you make the script executable you can just write ./script