in reply to changing record separator to all my perl programs

What operating system are you using? And where does your data come from?

When Perl is built it should set up the correct value for $/ by default. If that hasn't happened then there is something very strange about your Perl installation.

One way that I can think of for this effect to happen, is if you are running your programs on Windows (which uses \r\n as the line end marker) but that your data is generated on some version of Unix (which uses \n). In that case, your Windows programs won't ever recognise the Unix line end characters. If this is the case then really the conversion of the line end characters should be dealt with by the file transfer mechanism (for example, using FTP in ASCII mode.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re: changing record separator to all my perl programs

Replies are listed 'Best First'.
Re^2: changing record separator to all my perl programs
by blazar (Canon) on Oct 13, 2006 at 09:22 UTC
    One way that I can think of for this effect to happen, is if you are running your programs on Windows (which uses \r\n as the line end marker) but that your data is generated on some version of Unix (which uses \n). In that case, your Windows programs won't ever recognise the Unix line end characters. If this is the case then really the conversion of the line end characters should be dealt with by the file transfer mechanism (for example, using FTP in ASCII mode.

    This does not seem to be the case:

    C:\temp>cat -A foo.txt foo$ bar$ baz$ C:\temp>perl -le "chomp(@a=<>);print for map qq|<$_>|, @a" foo.txt | c +at -A <foo>^M$ <bar>^M$ <baz>^M$

    Oh, and for completeneess, the other way round:

    tilde:~ [11:19:27]$ cat -A foo.txt foo^M$ bar^M$ baz^M$ tilde:~ [11:19:47]$ perl -le 'chomp(@a=<>);print for map qq|<$_>|, @a' + foo.txt | cat -A <foo^M>$ <bar^M>$ <baz^M>$
Re^2: changing record separator to all my perl programs
by ikegami (Patriarch) on Oct 13, 2006 at 18:06 UTC
    Windows may use CRLF for the end of line marker, but $/ is set to LF on Windows. When reading, Perl converts CRLF to LF (except in binary mode). This happens before searching for the end of the line, so setting $/ to "\r\n" would not work. It also means that Perl can read UNIX files no problem. (On the other hand, unix doesn't read Windows files correctly.)