[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: str1 = str2 is not a copy?!?

Gavin Kistner

11/2/2006 9:22:00 PM

From: Austin Ziegler [mailto:halostatue@gmail.com]
> > BTW, is there a foreach function that automatically strips off the
> > newlines from line? Returning the record separators is silly.
>
> No, it isn't silly. Sometimes, that's what people want. You should be
> using #chomp or #chomp! to strip that (use #strip or #strip!
> if and only if you want to remove whitespace from beginning and end of
the line).

I would argue that this claim is subjective. I personally feel that it
is silly, akin to if String#split left the delimiters at the end of each
match.

(And there's one answer, Joe. If you can handle slurping the whole file
into memory, perhaps instead use something like:
IO.read( data_file ).split( $/ ).each{ |line| ... }
to process your data.)