[#1026] Is this a bug? — Dave Thomas <Dave@...>

18 messages 2000/01/03

[#1084] Infinite loop — Dave Thomas <Dave@...>

17 messages 2000/01/11

[#1104] The value of while... — Dave Thomas <Dave@...>

24 messages 2000/01/11

[ruby-talk:01205] Re: Semantics of chomp/chop

From: Dave Thomas <Dave@...>
Date: 2000-01-31 03:36:13 UTC
List: ruby-talk #1205
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/

In This Thread

Prev Next