in reply to $. - smarter than you might think
You can even assign to it and cheat about the line number:
BTW, the DATA filehandle is funny as well. This prints it's source along with line numbers (perl 5.8.8):#!/usr/bin/perl <DATA>; $.= 39; print "$. $_" while <DATA>; __DATA__ line 1 line 2 line 3
gives#!/usr/bin/perl seek DATA,0,0; print "$. $_" while <DATA>; __DATA__ line 1 line 2 line 3
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}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: $. - smarter than you might think
by GrandFather (Saint) on Jun 22, 2006 at 22:53 UTC | |
by shmem (Chancellor) on Jun 22, 2006 at 23:13 UTC | |
by radiantmatrix (Parson) on Jun 26, 2006 at 15:56 UTC | |
by shmem (Chancellor) on Jun 26, 2006 at 16:23 UTC |
In Section
Meditations