Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Why $NR and $INPUT_LINE_NUMBER are not the same as $.?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Peng Yu, post: 4873273"] I have the following perl script. $ cat main.pl #!/usr/bin/env perl #use warnings; while(<STDIN>) { print "#$_"; print "\$INPUT_LINE_NUMBER=$INPUT_LINE_NUMBER\n"; print "\$NR=$NR\n"; print "\$.=$.\n"; } However, the output shows that $NR and $INPUT_LINE_NUMBER are not the same as $.. According to my understand, these three variable should be the same. Would you please let me know why they are not the same in this case? And how to make them the same? $ ./main.pl < main.pl ##!/usr/bin/env perl $INPUT_LINE_NUMBER= $NR= $.=1 # $INPUT_LINE_NUMBER= $NR= $.=2 ##use warnings; $INPUT_LINE_NUMBER= $NR= $.=3 # $INPUT_LINE_NUMBER= $NR= $.=4 #while(<STDIN>) { $INPUT_LINE_NUMBER= $NR= $.=5 # print "#$_"; $INPUT_LINE_NUMBER= $NR= $.=6 # print "\$INPUT_LINE_NUMBER=$INPUT_LINE_NUMBER\n"; $INPUT_LINE_NUMBER= $NR= $.=7 # print "\$NR=$NR\n"; $INPUT_LINE_NUMBER= $NR= $.=8 # print "\$.=$.\n"; $INPUT_LINE_NUMBER= $NR= $.=9 #} $INPUT_LINE_NUMBER= $NR= $.=10 # $INPUT_LINE_NUMBER= $NR= $.=11 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Why $NR and $INPUT_LINE_NUMBER are not the same as $.?
Top