What do N and R in $NR stand for?

P

Peng Yu

I know $NR is the same as $INPUT_LINE_NUMBER. But I'm wondering what N
and R in NR stand for.

I think R might stand for numbeR? Does N stand for iNput or liNe?
 
U

Uri Guttman

PY> I know $NR is the same as $INPUT_LINE_NUMBER. But I'm wondering what N
PY> and R in NR stand for.

PY> I think R might stand for numbeR? Does N stand for iNput or liNe?

Number of Records. it was inherited from awk which has the same variable
NR (from the awk man page):

NR The total number of input records seen so far.

and that also works as the line number so they are the same thing with
different names for historical reasons.

it helps when learning perl to know its major influences which are c,
shell and awk. c is still used as is shell. awk is pretty much a side
player if at all today but when i first learned perl, awk was in heavy
use. in any case many awkish things are in perl such as some names, the
range operator (scalar mode), hashes, the -p option loop, etc.

uri
 
S

sachin

I presume you are using the English module? I would recommend against
it. Quite apart from the minor performance penalty (which can be avoided
with newer versions of English) the puncuation names are much more
familiar to most Perl programmers.

Ben

I believe if the record separator is '\n', and which is by default,
then NR would be same as number of lines. However, if we set the
record separator or delimiter as some other character, then value of
NR might be different.

Please correct me if I am wrong.

Regards,
Sachin
 
U

Uri Guttman

s> I believe if the record separator is '\n', and which is by default,
s> then NR would be same as number of lines. However, if we set the
s> record separator or delimiter as some other character, then value of
s> NR might be different.

s> Please correct me if I am wrong.

the name is Number of Records. a line is only a record if \n is the
value of $/. so $NR (or more commonly $.) is always correct from that
point of view. if you are reading lines, it is also the line number. so
your point is not really on target.

uri
 
S

sln

s> I believe if the record separator is '\n', and which is by default,
s> then NR would be same as number of lines. However, if we set the
s> record separator or delimiter as some other character, then value of
s> NR might be different.

s> Please correct me if I am wrong.

the name is Number of Records. a line is only a record if \n is the
value of $/.

But a record is not dependent upon a newline, therefore the value of
$/ is just a line separator in the menutia of file i/o and nothing else.

-sln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top