http://www.perlmonks.org?node_id=557033


in reply to $. - smarter than you might think

You can even assign to it and cheat about the line number:
#!/usr/bin/perl <DATA>; $.= 39; print "$. $_" while <DATA>; __DATA__ line 1 line 2 line 3
BTW, the DATA filehandle is funny as well. This prints it's source along with line numbers (perl 5.8.8):
#!/usr/bin/perl seek DATA,0,0; print "$. $_" while <DATA>; __DATA__ line 1 line 2 line 3
gives
1 #!/usr/bin/perl 2 3 seek DATA,0,0; 4 print "$. $_" while <DATA>; 5 __DATA__ 6 7 line 1 8 line 2 9 line 3

Bug or feature? :-)

cheers,
--shmem

Update: this is covered implicitly in perl561delta, Potential to leak DATA filehandles:

Using the "__DATA__" token creates an implicit filehandle to th +e file that contains the token. It is the program's responsibility to + close it when it is done reading from it.

_($_=" "x(1<<5)."?\n".q/)Oo.  G\        /
                              /\_/(q    /
----------------------------  \__(m.====.(_("always off the crowd"))."
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}