develooper Front page | perl.perl5.porters | Postings from November 1999

Re: [ID 19991119.003] chomp() can be confusing

Thread Previous | Thread Next
Chris Nandor
November 22, 1999 07:08
Re: [ID 19991119.003] chomp() can be confusing
Message ID:
At 07.54 -0700 1999.11.22, Tom Christiansen wrote:
>>The suggestion that I heard which I most like is letting $/ be an RE.  So
>>you can make $/ be /\n|\r\n?/ and it magically "does the right thing" on
>>virtually any file.  However integrating this logic into the RE engine
>>could be interesting.  After all if you apply the pattern I gave to a
>>string that ends with \r, it will match even if the next character to be
>>read is \n.  This is manifestly not the right thing to do. :-(
>Anything that deviates from the notion of internally representing the
>line terminator as a single character (the virtual "\n") is a grave error.

I had another idea ... which maybe completely useless, but it is
interesting to think about.  If $/ is a regex, then it is only a regex
until it matches the first time, at which point $/ becomes equal to $1.  So:

   $/ = qr/(\015?\012|\015)/;

As soon as it sees \015\012, \012, or \015, $/ becomes whatever it matched.
Again, this would require per-filehandle IRS to be useful.  Not advocating,
just throwing it out for fun.  :D

Chris Nandor
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About