"David Douthitt" <DDouthitt / cuna.com> writes:

> I was looking at the documentation for chomp and chomp! - and the
> results of chomp startled me to say the least.
> 
> $_ = "now\n"
> p chomp
> p $_
> p chomp "ow"
> p $_
> 
> printed:
> 
> "now"
> "now"
> "n"
> "n"
> 
> I would have expected:
> 
> "now"
> "now"
> "ow"
> "ow"
> 
> Is this not better?

Maybe, but it wouldn't be 'chomp'. Chomp removes the given string
(defaulting to a newline) from the end of another string (in this case 
$_). It's typically used to remove newlines from stuff you read in:

   while gets
     chomp
     # do stuff with $_
   end

This is a a bone unashamedly thrown to the Perl converts.

> Also, the description for chomp! appears to be the same as for chomp
> - which it is not after CAREFUL examination.

The reference pages have a fairly substantial difference:
(http://dev.rubycentral.com/ref/ref_m_kernel.html#chomp!)


chomp:
       Equivalent to $_.chomp!(aString), except nil is never
       returned. If $_ is changed, the new version is returned,
       otherwise a copy of the original value is returned. See
       String#chomp! on page 1.

chomp!:
       Equivalent to $_.chomp!(aString). See String#chomp! 


Am I missing something--I'm keen to make these reference pages as
accurate as possible.


Dave