From: "David A. Black" Date: 2004-02-24T07:06:47+09:00 Subject: Re: Need examples comparing Ruby to Python Hi -- On Tue, 24 Feb 2004, Jim Weirich wrote: > > 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} ^^ s/it/t/ :-) (I wonder whether it would be faster/slower/same to do: f,l,n,t = line.squeeze.split('|').collect{|t| t.strip} but I'm feeling too lazy to haul out benchmark.rb right now :-) David -- David A. Black dblack@wobblini.net