[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: Re: why won't ruby chomp for me?
From: ts <decoux () moulon ! inra ! fr>
Date: 2004-01-29 15:19:13
Message-ID: 200401291519.i0TFJ8d15618 () moulon ! inra ! fr
[Download RAW message or body]
>>>>> "E" == Emmanuel Touzery <emmanuel.touzery@wanadoo.fr> writes:
E> I was wondering.. IIRC, Perl came up with this "\n" in the end of
E> line in gets etc because in Perl, "" is false. So, if you want to have:
E> while (<>) {print $_;}
E> working, you needed that even empty lines won't be "false". So they
E> said that they will put the "\n" in the line, and problem is gone, nice
E> hack etc.
Well, I know nothing in this strange P language but this is not really the
reason.
while (<>) {} is in reality a shortcut for while(defined($_ = <>)) {} (it
must exist an old version of this strange language where while($_ = <>) {}
was different from while (<>) {})
The reason is that if the file don't end with a newline, like you say ""
is false but defined("") is true
E> but in ruby, "" is true, so i'm wondering... why did ruby take this
E> over from perl? i find myself many times forgetting that chomp and the
E> fact ruby offers me the "raw" line format never ever helped me in any
E> way.
Probably the good question is : what is a line ? do the "line" separator
belong to the line or not ?
Guy Decoux
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic