A couple of questions from a Ruby neophyte

Chad Perrin wrote:
>So far (which isn't too far yet), Ruby's
>regex support is a very close second to Perl's, in my opinion. In fact,
>there are a couple things I think Ruby does better.
>
This is probably a FAQ, but just how different *are* Perl and Ruby regex
capabilities? I'm not a heavy regex user by any stretch of the
imagination. I do the basic stuff that will work anywhere (original
"vi", "grep", "sed", "awk") so Perl and Ruby are overkill for me.

For the most part, they're pretty similar. There are a few differences
that can trip you up, though -- for instance, in Ruby this works for
matching either foo or bar:

  /foo|bar/

. . . whereas in Perl you'd need to do this:

  /(foo|bar)/

To be really correct, unless you wanted to capture the match in a
variable, you'd do this in Perl:

  /(?:foo|bar)/

. . . since without the "?:" you would get the match of "foo|bar" stored
in the $1 variable. Not a big deal normally, but if you're iterating
over a list of thousands, and you don't need the variable captures, but
performance is important, unneeded capture of matches in variables might
create a performance hit.

Also, Perl has nothing that looks like this:

  string.gsub(/foo/, 'bar')

Instead, you'd just do this:

  string =~ s/foo/bar/g;

>. . . though I'll probably come back to it and really learn Python at
>some point in the distant future. You know, when I'm done with Ruby,
>UCBLogo, Objective Caml, Objective C, Common Lisp, Scheme, Haskell, Perl
>6, and refamiliarizing myself with C. I'm pretty sure refamiliarizing
>myself with Java comes after Python, though.
>
Awww ... you left off Forth :wink: It was an accident, I trust. :wink:

Umm . . . sure.

Truth be told, Forth hasn't really made it onto my radar. On the other
hand, if it makes you feel better, you might just assume that Forth is
one of the languages I already know, so that it didn't need to be
mentioned.

···

On Sun, Mar 11, 2007 at 02:32:13AM +0900, M. Edward (Ed) Borasky wrote:

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
This sig for rent: a Signify v1.14 production from http://www.debian.org/

Really?

$ perl -e '$_ = "abcfoodef"; print "match!\n" if /foo|bar/'
match!
$ perl -v | head -3

This is perl, v5.8.7 built for i486-linux-gnu-thread-multi
(with 1 registered patch, see perl -V for more detail)

···

On Sun, Mar 11, 2007 at 04:42:19AM +0900, Chad Perrin wrote:

> This is probably a FAQ, but just how different *are* Perl and Ruby regex
> capabilities? I'm not a heavy regex user by any stretch of the
> imagination. I do the basic stuff that will work anywhere (original
> "vi", "grep", "sed", "awk") so Perl and Ruby are overkill for me.

For the most part, they're pretty similar. There are a few differences
that can trip you up, though -- for instance, in Ruby this works for
matching either foo or bar:

  /foo|bar/

. . . whereas in Perl you'd need to do this:

  /(foo|bar)/

Wow. All this time, I thought the parentheses were necessary.

Funny.

Thanks for disabusing me of that notion.

···

On Sun, Mar 11, 2007 at 05:17:24AM +0900, Brian Candler wrote:

On Sun, Mar 11, 2007 at 04:42:19AM +0900, Chad Perrin wrote:
> > This is probably a FAQ, but just how different *are* Perl and Ruby regex
> > capabilities? I'm not a heavy regex user by any stretch of the
> > imagination. I do the basic stuff that will work anywhere (original
> > "vi", "grep", "sed", "awk") so Perl and Ruby are overkill for me.
>
> For the most part, they're pretty similar. There are a few differences
> that can trip you up, though -- for instance, in Ruby this works for
> matching either foo or bar:
>
> /foo|bar/
>
> . . . whereas in Perl you'd need to do this:
>
> /(foo|bar)/

Really?

$ perl -e '$_ = "abcfoodef"; print "match!\n" if /foo|bar/'
match!
$ perl -v | head -3

This is perl, v5.8.7 built for i486-linux-gnu-thread-multi
(with 1 registered patch, see perl -V for more detail)

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts." - Paul Graham