in reply to $/ and DOS files

Even though the file contains "\r\n", the Perl script sees a plain "\n" when reading from the file, by default. Translation of EOLN marks is done on a more primitive level, so no matter what OS you are on, you use "\n" in Perl.

(to disable that, use binmode)

Replies are listed 'Best First'.
Re: Re: $/ and DOS files
by fxia (Novice) on Jul 23, 2001 at 23:10 UTC
    But my case is to process the DOS file on a UNIX system. So the perl won't see \r\n the same as \n. If I do the truncation, it does work. But then I think it is a performance hit. I just wonder if there is any better way to do it.
      As noted in another message, you can't compose a value to $/ that works like the magic built-in paragraph mode.

      So, you could implement a filter, and read from that filter. Or, slurp in the whole file and use split, which does allow regex for the delimiter. That is easy and speedy, if your file is small enough so memory is not an issue.

      Something like:

      my @lines= split (/(?:\r?\n){2,}/, do { local $/; <INPUT>}); # lines already chomped, since delimiter not included.
      —John