Prev: FAQ 4.10 Why aren't my random numbers random?
Next: Why $NR and $INPUT_LINE_NUMBER are not the same as $.?
From: Peng Yu on 22 May 2010 15:13 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?
From: Uri Guttman on 22 May 2010 15:22 >>>>> "PY" == Peng Yu <pengyu.ut(a)gmail.com> writes: 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 -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Ben Morrow on 22 May 2010 16:36 Quoth Peng Yu <pengyu.ut(a)gmail.com>: > 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? 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
From: sachin on 24 May 2010 02:25 On May 23, 1:36 am, Ben Morrow <b...(a)morrow.me.uk> wrote: > Quoth Peng Yu <pengyu...(a)gmail.com>: > > > 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? > > 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
From: Uri Guttman on 24 May 2010 03:17 >>>>> "s" == sachin <reachsachin(a)gmail.com> writes: s> On May 23, 1:36�am, Ben Morrow <b...(a)morrow.me.uk> wrote: >> Quoth Peng Yu <pengyu...(a)gmail.com>: >> >> > 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? >> >> 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 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 -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
|
Next
|
Last
Pages: 1 2 Prev: FAQ 4.10 Why aren't my random numbers random? Next: Why $NR and $INPUT_LINE_NUMBER are not the same as $.? |