On Fri, Feb 22, 2013 at 12:08 PM, Tiago Hori <tiago.h...@gmail.com> wrote:

> What I was wondering is: is there any way to force perl to use other line
> ending characters, like MacOS CR?
>

 Perl's "magic" var "$/" or via "use English" $RS or
$INPUT_RECORD_SEPARATOR (Larry's mnemonic "as in poetry or think a mad
<i>slasher</i> slashing the line to ribbons") can be set to any char (or
undef for slurping).
{
    local $/ = "\r";
    while (<>) {   # read Mac-ishly
...

the convention is to use a code block and "local" to keep from causing
problems elsewhere.  Normally Perl is pretty good at figuring that out.
You also may want to look at the perldoc for binmode.
  binmode FILEHANDLE, LAYER
       binmode FILEHANDLE
        Arranges for FILEHANDLE to be read or written in "binary" or "text"
mode
        on systems where the run-time libraries distinguish between binary
and
        text files.  If FILEHANDLE is an expression, the value
        is taken as the name of the filehandle.  Returns true on success,
        otherwise it returns "undef" and   sets $! (errno).

       On some systems (in general, DOS and Windows-based systems)
       binmode() is necessary when you’re not working with a text file.
       For the sake of portability it is a good idea to always use it when
       appropriate, and to never use it when it isn’t appropriate.  Also,
       people can set their I/O to be by
       default UTF-8 encoded Unicode, not bytes.
...


-- 

a

Andy Bach,
afb...@gmail.com
608 658-1890 cell
608 261-5738 wk

Reply via email to