From: "Florian Groß" Date: 2003-07-24T11:43:38+09:00 Subject: Re: "regex literal in condition" Moin! Daniel Carrera wrote: > Thanks for the explanation, but I'm not quite following. > I now understand what a string literal is, but I don't quite get the > problem at the if. Well, in Ruby constructs like 'if /foo/' currently have a special meaning. It's not just a check to see whether '/foo/' is true as it is in all other cases (like, for example, 'if 5'). However in Perl 'if /foo/' really means 'if $_ =~ /foo/' and I guess that Ruby is just imitating that behaviour so that Perl users aren't suprised. I think that matz wants to deprecate this as it is a special case (and special cases are Bad Things) -- you could get the current behaviour without a warning with 'if ~/foo/': | ---------------------------------------------------------- Regexp#~ | ~ rxp -> anInteger or nil | ------------------------------------------------------------------- | Match---Matches rxp against the contents of $_. Equivalent to rxp | =~ $_. | $_ = "input data" | ~ /at/ #=> 7 To make long things short: 'if /foo/' should be replaced with 'if ~/foo/' when wanting to match. > Thanks for the help. No problem! :) Regards, flgr