[Melbourne-pm] The magic of shebang (was Re: programming tutorials: Perl)

wigs at stirfried.org wigs at stirfried.org
Tue Nov 16 15:22:38 PST 2010

On Mon, Nov 15, 2010 at 05:09:33PM +1100, Alec Clews wrote:
> [1] That was a lie. As a special case Perl will look at the line and use
> any flags it sees.

Just like English there are always exceptions to rules in Perl.  There is at
least one other special case where perl does not ignore lines starting with a
'#'.  Specifically, the '#line' pragma.

This tells the perl compiler to reset the source-code line counter.  For

 01 #!/bin/env perl -p
 02 use strict;
 04 #line 1001
 05 my $x = 2;
 05 $m = 1;

If you run that code an error will be reported in line 1002, and not line 5 as
you would otherwise expect.


More information about the Melbourne-pm mailing list