P
Peng Yu
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
$ 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