Shebang
You know that you can turn warnings on with -w on
the command line. You can also turn them on within the script itself. For that matter, you
can give perl any command line option within the script itself. For example:
perl script.pl hello
to execute this:
#!perl -w @input=@ARGV; $outfile='outfile.txt'; open OUT, ">$outfile" or die "Can't open $outfile for write:$!\n"; $input2++; $delay=2 if $input[0] eq 'sleep'; sleep $delay; print "The first element of \@input is $input[0]\n"; print OUY "Slept $delay!\n";
has the same effect as:
perl -w script.pl hello
It may be more convenient for you to put the flag inside the script. It doesn't have to be just -w , it can be any argument Perl supports. Run
perl -h
for a full list.
The first line, #!perl -w is the shebang line. This is derived from UNIX,
where Perl was first developed. UNIX systems make a script executable by changing an
attribute. The operating system then loads the file and works out how to execute it -- in
this case by looking at the first line, then loading the perl interpreter. Windows systems
know that all files with a certain extension must be passed to a certain program for
execution, eg all .bat files are passed to command.com, and all .xls
files are passed to Excel. The point of all this being that you don't need a shebang line,
but it doesn't hurt.