in reply to Line number in a file

You might consider this a nitpick, but the replies by pelagic and busunsl need a clarification.

To the best of my knowledge, the built-in Perl variable $. is technically the record number variable, not the line number variable, and a record is not always a line. It all depends upon the value of $/, the record separator variable. By default it is newline, but it can be changed.

I mention this only because I once had a terrible time debugging a (poorly written) script which read from a file, used $., and the script writer had changed the value of $/. It took me some time to figure that out.

davidj

Replies are listed 'Best First'.
Re^2: Line number in a file
by pelagic (Priest) on Jul 06, 2004 at 09:39 UTC
    >    It all depends upon the value of $/, the record separator variable.
    Of course if you read a file in slurp mode you actually just read 1 record and the official name INPUT_LINE_NUMBER is somewhat misleading because lines become a logical measure.
    And if you set $/ to some weird separator the meaning of line is actually set to something completely different.

    pelagic
Re^2: Line number in a file
by Anonymous Monk on Jul 07, 2004 at 06:32 UTC
    the script writer had changed the value of $/.
    I hope you berated gave him a "talking to" about not using local (appropriately).
      Well, I was considering requesting that his Perl privileges be temporarily suspended, but then, how could he learn to write better code. So, instead, I smacked him on the head with the Camel book :)

      davidj