Well I have downloaded Ruby and ordered the book, but I have
a question.  I am trying to get a sense for how Ruby works by
taking some moderately complex Perl code and translating it
into Ruby.  The code I chose is at:

http://www.perlmonks.org/index.pl?node_id=34786

Well everything in it is going to be fairly easy to translate
except the ability to loop over matches of an RE.  Looking
through a few FAQs I don't see that Ruby lets me do that.
What that I need are the ability to tell an RE that it should
match a string starting at X, and the ability to tell where
a match ended.  (I can figure out the latter from the match
info, but it is very handy to get that directly.)

An obvious "solution" is to walk through the string making a
copy of what is left at each step.  However doing that turns
what should be a O(n) scan through a string into O(n*n) work
due to recopying the string - which I find unacceptable.

This should be an easy thing to add to Ruby.  Just have a
method that returns where the last match left off, and to the
match operator add a second optional argument which is the
position in the string to start looking for a match at.  Add
a \G modifier like Perl's to indicate that the match must
start exactly at that position or fail.

With that and its existing control structures it should be
easy to build interesting text-processing stuff in Ruby which
are based on using REs to tokenize text.  Sure it would be
slightly cumbersome to use directly, but after someone wraps
it with some facilities for text-processing like SNOBOL has,
you wouldn't need to do that. :-)

For the record the concept of an optional second argument to
match is used in many languages.  (For instance JavaScript.)
Perl instead uses an implicit variable on the string
(accessable through pos()) and a ton of combinations of
context and reasons for matching to give you access to that.

If someone is really ambitious you might want to look at:

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-05/msg00853.html

and try to implement that optimization in Ruby's RE engine.
AFAIK no RE engine does that, but it generalizes quite a few.
Specifically with that optimization most of the information
in Mastering Regular Expressions by Friedl on potential
disaster REs should become passe. :-)

Hoping to get some sense of how smoothly Ruby works...

Cheers,
Ben
_____________________________________________________________________________________
Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com