[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Need examples comparing Ruby to Python
From:       "Jim Weirich" <jim () weirichhouse ! org>
Date:       2004-02-23 21:59:10
Message-ID: 40418.192.223.163.6.1077573539.squirrel () weirichhouse ! org
[Download RAW message or body]


David MacQuigg said:
> Here is what I would like to say in Python, but can't because
> line.split() produces a list, and the subsequent methods don't apply
> to lists.  I'll bet this would work in Ruby, but I don't know enough
> Ruby to say for sure.
>
> file, length, name, title = line.split('|').strip.split.join()
>
> The goal is to produce a list of strings with whitespace and newlines
> stripped off the ends, and whitespace squeezed out of the middle of
> each string.

Is this what you want ...

file, length, name, title = line.split('|').collect{|it| t.squeeze.strip}

-- 
-- Jim Weirich     jim@weirichhouse.org    http://onestepback.org
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic