From: tony summerfelt Date: 2006-08-14T21:00:22+09:00 Subject: Re: [good] Re: ruby equiv of perl pos On Mon, 14 Aug 2006 14:20:10 +0900, you wrote: >Logan Capaldo ha escrito: > >> How about: >> >> new_string = "" >> string.scan(/\0/) do |m| >> new_string = "%o" % $~.offset(0).first >> end > >That should work okay (well, it should be new_string << ..., thou). >I'll admit I was unaware of MatchData's offset method. That's cool. >Using string.scan() should be only slightly slower than the >while/index() loop do to the inherent yield in scan {}. >If you are comming from Perl, I would also recommend to stick with >Regexp.last_match instead of $~ for clarity. I did 5+ years of Perl >but I'll be damned if I remember what all the $symbol vars stand for >without looking them up. > http://home.cogeco.ca/~tsummerfelt1 ROVING SWARM: http://groups.yahoo.com/group/roving_swarm/ telnet://ventedspleen.dyndns.org