hi,
this is a warning i got while playing around with yaml.
ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be obsolete;
use explicit regexp
why??
without =~ matching strings will not be so much fun again .
···
–
- mr
hi,
this is a warning i got while playing around with yaml.
ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be obsolete;
use explicit regexp
why??
without =~ matching strings will not be so much fun again .
–
“meinrad.recheis” my.name.here@gmx.at writes:
ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be
obsolete; use explicit regexpwhy??
without =~ matching strings will not be so much fun again
.
This is the case that’s becoming obselete:
irb(main):001:0> “foo” =~ “foo”
(irb):1: warning: string =~ string will be obsolete; use explicit regexp
This should still work:
irb(main):002:0> “foo” =~ /bar/
=> nil # No warning.
Dan
–
/^Dan Debertin$/ |
airboss@nodewarrior.org |
www.nodewarrior.org |
=~ isn’t going away.
=~ “something” is going away.
What you want to do is always match a regex, i.e.:
variable =~ /something/
On Aug 9, meinrad.recheis wrote:
hi,
this is a warning i got while playing around with yaml.ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be obsolete;
use explicit regexpwhy??
without =~ matching strings will not be so much fun again
.
–
- mr
In article oprtlut5x0edtuaz@news.tuwien.ac.at,
[…]
: ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be obsolete;
: use explicit regexp
:
: why??It’s string =~ string which is being obsoleted. If you need to
That’s “why the error message?”. What about “Why will it be
obsolete?”?
Hugh
In article oprtlut5x0edtuaz@news.tuwien.ac.at,
[…]
: ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be
obsolete;
: use explicit regexp
:
: why??It’s string =~ string which is being obsoleted. If you need to
That’s “why the error message?”. What about “Why will it be
obsolete?”?
Can’t answer that…
Why do you need or want string-string as opposed
to string-regex? Not a flame, just a question.
Hal
----- Original Message -----
From: “Hugh Sasse Staff Elec Eng” hgs@dmu.ac.uk
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 08, 2003 7:02 PM
Subject: Re: =~ obsolete?
On Sat, 9 Aug 2003, Dave Brown wrote:
meinrad.recheis my.name.here@gmx.at wrote:
–
Hal Fulton
hal9000@hypermetrics.com
Hi,
That’s “why the error message?”. What about “Why will it be
obsolete?”?
Because it’s confusing. Where both
/pattern/ =~ string
and
string =~ /pattern/
what do you expect from
string1 =~ string2
which side should be the pattern?
matz.
In message “Re: =~ obsolete?” on 03/08/09, Hugh Sasse Staff Elec Eng hgs@dmu.ac.uk writes:
Dunno, maybe because your (mmv, too) principle of least surprise (yes yes
I’m not argueing based on it, just offering a view!) told you that finding
a substring in a string doesn’t need regexes which smell like being awfully
slower than plain string searches and the hope that
string =~ string
is something like
string[string]
At least that’s why I’d try to use it (if not someone recently pointed out
string[string] (again!))…
-Martin
On Sat, Aug 09, 2003 at 09:06:59AM +0900, Hal E. Fulton wrote:
----- Original Message -----
From: “Hugh Sasse Staff Elec Eng” hgs@dmu.ac.uk
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 08, 2003 7:02 PM
Subject: Re: =~ obsolete?On Sat, 9 Aug 2003, Dave Brown wrote:
In article oprtlut5x0edtuaz@news.tuwien.ac.at,
meinrad.recheis my.name.here@gmx.at wrote:
[…]
: ruby/lib/ruby/1.8/yaml.rb:28: warning: string =~ string will be
obsolete;
: use explicit regexp
:
: why??It’s string =~ string which is being obsoleted. If you need to
That’s “why the error message?”. What about “Why will it be
obsolete?”?Can’t answer that…
Why do you need or want string-string as opposed
to string-regex? Not a flame, just a question.
Hi,
That’s “why the error message?”. What about “Why will it be
obsolete?”?Because it’s confusing. Where both
[…]
what do you expect fromstring1 =~ string2
which side should be the pattern?
Thank you. The reason was what I wanted, and this improves clarity
of code, so is a good reason. I don’t think I’ve ever used strings
on both sides of =~ myself, but I was curious about why the change
was planned.
matz.
Thank you,
Hugh
On Sat, 9 Aug 2003, Yukihiro Matsumoto wrote:
In message “Re: =~ obsolete?” > on 03/08/09, Hugh Sasse Staff Elec Eng hgs@dmu.ac.uk writes:
Why do you need or want string-string as opposed
to string-regex? Not a flame, just a question.Dunno, maybe because your (mmv, too) principle of least surprise (yes yes
I’m not argueing based on it, just offering a view!) told you that finding
a substring in a string doesn’t need regexes which smell like being
awfully
slower than plain string searches and the hope thatstring =~ string
is something like
string[string]
At least that’s why I’d try to use it (if not someone recently pointed out
string[string] (again!))…
But that’s not the same thing…
“abc” =~ “c” # 2 (index)
“abc”[“c”] # “c”
But more importantly, the second string is not
a substring; it’s really a regex stored in a
string:
“abc” =~ “…” # 0
“abc”[“…”] # nil
Perhaps the rationale for the obsolescence is that you shouldn’t
pretend to be using a string when you’re really using a regex.
Hal
----- Original Message -----
From: “Martin Weber” Ephaeton@gmx.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, August 08, 2003 7:17 PM
Subject: Re: =~ obsolete?
–
Hal Fulton
hal9000@hypermetrics.com
This does not find a substring in a string. The RHS is transformed into
a regexp first. You can see it in this example:
irb(main):002:0> ‘abcdef’ =~ ‘b(.)e’ and $1
(irb):2: warning: string =~ string will be obsolete; use explicit regexp
=> “cd”
irb(main):003:0> 'b(.)e’ =~ ‘abcdef’ and $1
(irb):3: warning: string =~ string will be obsolete; use explicit regexp
=> nil
I think that’s an unpleasant surprise and it should not be allowed. It
smells like Perl’s => operator which magically quotes (some) strings on
the LHS.
On 2003-08-09 09:17:10 +0900, Martin Weber wrote:
Dunno, maybe because your (mmv, too) principle of least surprise (yes
yes I’m not argueing based on it, just offering a view!) told you that
finding a substring in a string doesn’t need regexes which smell like
being awfully slower than plain string searches and the hope thatstring =~ string
–
If you pick up a starving dog and make him prosperous, he will not bite
you; that is the principal difference between a dog and a man.
– Mark Twain
Why do you need or want string-string as opposed
to string-regex? Not a flame, just a question.Dunno, maybe because your (mmv, too) principle of least surprise (yes yes
I’m not argueing based on it, just offering a view!) told you that finding
a substring in a string doesn’t need regexes which smell like being
awfully
slower than plain string searches and the hope thatstring =~ string
is something like
string[string]
At least that’s why I’d try to use it (if not someone recently pointed out
string[string] (again!))…But that’s not the same thing…
It is …
“abc” =~ “c” # 2 (index)
not nil
“abc”[“c”] # “c”
not nil
see ?
if (input =~ “bigfatsecretsupergodmodewithstillplayfun!”) then …
But more importantly, the second string is not
a substring; it’s really a regex stored in a
string: (…)
If you MEAN a regexp but write a string instead… which you don’t (you want
no regexp, but all string matching you did that far was with =~). If you MEAN
a substring tho …
-martin
On Sat, Aug 09, 2003 at 09:26:40AM +0900, Hal E. Fulton wrote:
Dunno, maybe because your (mmv, too) principle of least surprise (yes
yes I’m not argueing based on it, just offering a view!) told you that
finding a substring in a string doesn’t need regexes which smell like
being awfully slower than plain string searches and the hope that
^^^^string =~ string
Maybe should’ve underlined that in my first mail, too
This does not find a substring in a string. The RHS is transformed into
a regexp first. You can see it in this example:
Iiiiii know, the question was why would you come to the idea of trying to
use a string on the right hand side. Next. throw ‘hint’.
-martin
On Sat, Aug 09, 2003 at 09:41:52AM +0900, Florian Frank wrote:
On 2003-08-09 09:17:10 +0900, Martin Weber wrote:
I think this behaviour was stolen from Perl. Perl is cluttered with
special syntax magic like this. That makes it really hard to learn
what’s going on. I like Ruby’s =~ operator better than Perl’s because I
tended to swap both sides while coding and used /foo/ =~ “bar”. Ruby’s
=~ is commutative (with the striing exception), so it doesn’t matter
anymore.
On 2003-08-09 09:54:36 +0900, Martin Weber wrote:
Iiiiii know, the question was why would you come to the idea of trying
to use a string on the right hand side. Next. throw ‘hint’.
–
Do not fear to be eccentric in opinion, for every opinion now accepted was
once eccentric.
– Bertand Russell