=~ obsolete?

D

Dan Debertin

meinrad.recheis said:
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 :( .

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
 
M

meinrad.recheis

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 :( .
 
D

Dave Brown

: 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??

It's string =~ string which is being obsoleted. If you need to
match a string against a string, use

string =~ Regexp.new(otherstring)

instead.

--Dave
 
H

Hugh Sasse Staff Elec Eng

: 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?"?
 
H

Hal E. Fulton

----- Original Message -----
From: "Hugh Sasse Staff Elec Eng" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Friday, August 08, 2003 7:02 PM
Subject: Re: =~ obsolete?

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
 
M

Martin Weber

----- Original Message -----
From: "Hugh Sasse Staff Elec Eng" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Friday, August 08, 2003 7:02 PM
Subject: Re: =~ obsolete?



Can't answer that...

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 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
 
H

Hal E. Fulton

----- Original Message -----
From: "Martin Weber" <[email protected]>
To: "ruby-talk ML" <[email protected]>
Sent: Friday, August 08, 2003 7:17 PM
Subject: Re: =~ obsolete?

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 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!))...

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
 
M

Martin Weber

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 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!))...

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
 
F

Florian Frank

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

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.
 
M

Martin Weber

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
 
F

Florian Frank

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'.

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. ;)
 
D

Dave Brown

:
: > In article <[email protected]>,
: [...]
: > : 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?"?

string =~ string actually does string =~ Regexp.new(string)
internally. So it's better to make you make it explicit instead
of doing Magic Stuff behind your back.

It's for consistency's sake as much as anything else.

--Dave
 
Y

Yukihiro Matsumoto

Hi,

In message "Re: =~ obsolete?"

|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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top