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

[MacPerl] Re: Recognizing Unix Line Breaks



Lasse Hiller¿e Peterson <lassehp@imv.aau.dk> wrote
{...}
>As I said in my first reply on this, there is a suboptimal solution to this
>(use \012 to mean LF, \015 to mean CR, and $/ to mean platform-specific
>line break, changing it when necessary), which only requires a little extra
>effort of the programmer (and the extra time it takes to figure out when a
>module you didn't write yourself forces $/ to \n behind your back.)
{snip}

Maybe what's needed is an I/O streams module which replaces the standard
I/O semantics (as "use integer" does the standard arithmetic semantics).
Give fopen() an extra parameter when the module is used-- a reference to a
variable containing the line-break string to use; when opening a file for
input, fopen() would set this variable (via the reference passed in the
call to fopen).  Then, calls to <FILEHANDLE> and print FILEHANDLE ...
could implicitly do s/$$LineBreakRef/\n/g and s/\n/$$LineBreakRef/g,
respectively.  The default input and output operators (<> and print ...)
could be handled based on the line-break string associated with whichever
filehandle is currently associated with <>.  An additional function, say
fsetlnbk(FILEHANDLE,\$LineBreak), could allow for those bizarre cases in
which a programmer might want to change line-break conventions in mid-
file. :-)

This approach would leave a little room for confusion, if someone felt
absolutely compelled to use both <> and print ... on a set of input files
that might use two or more different line-break conventions, but it would
take a determined effort on the part of a programmer to get into trouble
that way.  (e.g.: snarfing all of <> into a single string or array before
doing any output, and then expecting the output to preserve the line-break
conventions of the respective input files).

So, how does this idea strike people?  What's wrong with it?  Who would
want to use it?  Does anybody with enough free time want to do it right
now, or should I add to my "to do as time permits" queue?

- Bill Hazelrig (haz1@nwu.edu)



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