in reply to Re: Tiptoe through the punctuation
in thread Tiptoe through the punctuation

Well done!

$. is also known as $INPUT_LINE_NUMBER and is to be considered read-only. It is undefined until you read from a filehandle or it is assigned to by your program. If you assign a value to $. and then read from a filehandle, it will be reset to its proper value by Perl.

Example:

#!/usr/bin/perl -w use strict; print "\$. is ", $., $/; $. = 9999; print "\$. is now ", $., $/; print "Press <enter> to continue.\n"; my $input = <>; print "\$. is now ", $., $/;

Replies are listed 'Best First'.
Re: $. explained
by tye (Sage) on Mar 11, 2003 at 18:15 UTC

    Almost correct.

    You can motify $. but you first have to have it pointing to the correct file handle:

    print "($.)\n"; # undefined $. = 10; print "($.)\n"; # 10, but for which file handle? print "ENTER: "; ''.<STDIN>; print "($.)\n"; # 1, for STDIN $. += 10; print "($.)\n"; # 11, still for STDIN print "ENTER: "; ''.<STDIN>; print "($.)\n"; # 12, not 2 !

                    - tye