commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chaffee / Purple Technology <g...@stinky.com>
Subject Re: [lang] chop and chomp
Date Wed, 05 Mar 2003 21:24:14 GMT
On Wed, Mar 05, 2003 at 12:59:28PM -0800, Morgan Delagrange wrote:
> 
> --- Alex Chaffee / Purple Technology <guru@stinky.com>
> wrote:
> > 
> > Perl:
> > 
> > chop removes the final character, no matter what it
> > is
> > 
> > chomp removes the final character if and only if
> > it's a newline
> > (or, technically, the $INPUT_RECORD_SEPARATOR).
> > 
> 
> Technically, that's incorrect.  Perl's chomp command
> deletes all consecutive substrings matching the
> $INPUT_RECORD_SEPARATOR from the end of the string. 

I admit I'm always confused about these details, so let's ask Perl:

[alex@meat jakarta-commons]$ perl -e '$x = "foo"; chomp($x); print $x;'
foo[alex@meat jakarta-commons]$ perl -e '$x = "foo\n"; chomp($x); print $x;'
foo[alex@meat jakarta-commons]$ perl -e '$x = "foo\n\n\n\n"; chomp($x); print $x
foo


[alex@meat jakarta-commons]$

So it looks like it only chomps one separator, not all.

Perl also seems to glom \r\n; furthermore, I think that's the natural
expectation in the platform-independent world of Java.

-- 
Alex Chaffee                               mailto:alex@jguru.com
Purple Technology - Code and Consulting    http://www.purpletech.com/
jGuru - Java News and FAQs                 http://www.jguru.com/alex/
Gamelan - the Original Java site           http://www.gamelan.com/
Stinky - Art and Angst                     http://www.stinky.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message