ecuguru has asked for the wisdom of the Perl Monks concerning the following question:

I have to move a lot of datasets from Windows to Mac and back and forth, to be fed into Perl. I've noticed that when my Mac box tries to open up the Win data files with Open, and then For each (to handle each line in my code), that it will load the entire file into the first line, ignoring the line encodings. Same is true if I'm on my win box loading mac data.

I believe that Perl, by default, will look for the text encodings of the OS its running on. Can you manually change that for file input, or do I need to convert the text endings to windows (like replacing the \n with \r\n) first?

Also, for file write, it seems like all you really need to do is change the line endings (\n for mac, \r\n for win, \n for nix).Right?
Thanks!

Replies are listed 'Best First'.
Re: Perl file open files from other OS
by gri6507 (Deacon) on Sep 16, 2005 at 19:08 UTC
    yep, you can do local $/='\n'; (that's the input record separator) and then reading in should be fine. Also for writing files, you can do local $\="\r\n"; (that's the output record separator)
Re: Perl file open files from other OS
by shuchit (Novice) on Sep 16, 2005 at 20:50 UTC
    There's the open pragma and the three argument form of open using ":crlf:". However, you probably need a recent version of perl for this to work.