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

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

Thread Previous | Thread Next
From:
Chris Nandor
Date:
November 22, 1999 07:08
Subject:
Re: [ID 19991119.003] chomp() can be confusing
Message ID:
v04220800b45f0af4d87b@[192.168.0.7]
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          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About