in reply to Re: $/ and DOS files
in thread $/ and DOS files

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.

Replies are listed 'Best First'.
Re: Re: Re: $/ and DOS files
by John M. Dlugosz (Monsignor) on Jul 23, 2001 at 23:57 UTC
    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