What do N and R in $NR stand for?

Discussion in 'Perl Misc' started by Peng Yu, May 22, 2010.

  1. Peng Yu

    Peng Yu Guest

    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?
    Peng Yu, May 22, 2010
    #1
    1. Advertising

  2. Peng Yu

    Uri Guttman Guest

    >>>>> "PY" == Peng Yu <> 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 ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
    Uri Guttman, May 22, 2010
    #2
    1. Advertising

  3. Peng Yu

    sachin Guest

    On May 23, 1:36 am, Ben Morrow <> wrote:
    > Quoth 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?

    >
    > 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
    sachin, May 24, 2010
    #3
  4. Peng Yu

    Uri Guttman Guest

    >>>>> "s" == sachin <> writes:

    s> On May 23, 1:36 am, Ben Morrow <> wrote:
    >> Quoth 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?

    >>
    >> 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 ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
    Uri Guttman, May 24, 2010
    #4
  5. Peng Yu

    Guest

    On Mon, 24 May 2010 03:17:36 -0400, "Uri Guttman" <> wrote:

    >>>>>> "s" == sachin <> writes:

    >
    > s> On May 23, 1:36 am, Ben Morrow <> wrote:
    > >> Quoth 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?
    > >>
    > >> 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 $/.


    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
    , May 25, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nicc777
    Replies:
    2
    Views:
    641
  2. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,135
    robert
    Feb 11, 2006
  3. Replies:
    0
    Views:
    1,211
  4. Replies:
    7
    Views:
    435
    Andrew Thompson
    Feb 23, 2007
  5. Plotinus
    Replies:
    2
    Views:
    291
    Tad McClellan
    Dec 17, 2004
Loading...

Share This Page