[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Recognizing Unix Line Breaks



Jacob Miller <jacob@jacobco.com> writes:
}I'm quite an amatuer at perl.. so here's a (hopefully) simple question for
}you all.
}
}How can I get mac perl to regonize Unix line breaks as such..  it seems to
}read them in as an unknown character.  I do most of my text editing with
}BBEdit and its defaulted to Unix (as it saves a lot of frustration when
}uploading scripts and config files) .. but I have to change back over to
}Macintosh to import a file into Mac Perl.
}
}Any help would be greatly appreciated

MacPerl scripts cannot be written with Unix line breaks.  Text files with
Unix line breaks, however, can easily be processed with MacPerl.  All you
have to do is set the "input record separator" at the beginning of the
script to be \012:

$/ = "\012";

Now when reading a file line-by-line MacPerl (or any Perl) will consider
the Unix end-of-line to be what defines the end of a line.  If you need to
output a file with Unix line breaks, the easiest way is to simply say what
you mean:

print "something\012";

Don't use \n, since that always means \015, the Macintosh end-of-line, to
MacPerl.  The advantage of using \012 is that it will also work this way on
your Unix machine.

There's also an "output record separator", $\, that you can set to whatever
you want that will by default be appended to the end of any line printed
with print.  So you can say:

$\ = "\012";
print "something";

Personally I find that much less convenient than simply putting the
end-of-line in by hand.

Both $/ and $\ are global variables, so when you change them, it may affect
some things you didn't mean to affect.  You can localize the effect of a
change with local().

}
}Jacob
}
}.--- I N T E R N E T  S O L U T I O N S ---.
}|   Jacob & Co - http://www.jacobco.com/   |
}|     Email - mailto:jacob@jacobco.com     |
}+------------------------------------------+
}| RANDOM SIG: Be nice to your kids,they'll |
}| choose your nursing home                 |
}`------------------------------------------'
}
}
}
}***** Want to unsubscribe from this list?
}***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch


---
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693, Greenbelt, MD 20771
schinder@pjstoaster.pg.md.us



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch