matz / netlab.co.jp (Yukihiro Matsumoto) writes:

> Hi,
> 
> In message "[ruby-talk:01195] Re: Semantics of chomp/chop"
>     on 00/01/28, Dave Thomas <Dave / thomases.com> writes:
> 
> |I was wondering why copy it at all, as all four methods are allowed to 
> |alter $_.
> 
> They are different.  For exapmle:
> 
>   foo = $_ = "foo\n"
>   chomp
>   p foo  #=> "foo\n"  -- unchanged
>   p $_   #=> "foo"
> 
>   foo = $_ = "foo\n"
>   chomp!
>   p foo  #=> "foo"
>   p $_   #=> "foo"
> 
> See?  Non-bang versions leave original strings unchanged.

True enough - I wasn't thinking about an external reference to the
string.

A routine with a double side effect, one of which is remote! Scary!


Thanks once again

Dave



-- 
Thomas Consulting.
Innovative and successful developments with Unix, Java, C, and C++. 

Now in bookstores:
 The Pragmatic Programmer.  www.pragmaticprogrammer.com/ppbook/