=~ obsolete?

Discussion in 'Ruby' started by Dan Debertin, Aug 8, 2003.

  1. Dan Debertin

    Dan Debertin Guest

    "meinrad.recheis" <> writes:

    > 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
    --
    /^Dan Debertin$/ |
    |
    www.nodewarrior.org |
    Dan Debertin, Aug 8, 2003
    #1
    1. Advertising

  2. 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
    meinrad.recheis, Aug 8, 2003
    #2
    1. Advertising

  3. Dan Debertin

    Dave Brown Guest

    In article <>,
    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 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
    Dave Brown, Aug 9, 2003
    #3
  4. On Sat, 9 Aug 2003, Dave Brown wrote:

    > In article <>,
    > meinrad.recheis <> 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?"?
    >

    Hugh
    >
    Hugh Sasse Staff Elec Eng, Aug 9, 2003
    #4
  5. ----- Original Message -----
    From: "Hugh Sasse Staff Elec Eng" <>
    To: "ruby-talk ML" <>
    Sent: Friday, August 08, 2003 7:02 PM
    Subject: Re: =~ obsolete?


    > On Sat, 9 Aug 2003, Dave Brown wrote:
    >
    > > In article <>,
    > > meinrad.recheis <> 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.

    Hal

    --
    Hal Fulton
    Hal E. Fulton, Aug 9, 2003
    #5
  6. Dan Debertin

    Martin Weber Guest

    On Sat, Aug 09, 2003 at 09:06:59AM +0900, Hal E. Fulton wrote:
    > ----- Original Message -----
    > From: "Hugh Sasse Staff Elec Eng" <>
    > To: "ruby-talk ML" <>
    > Sent: Friday, August 08, 2003 7:02 PM
    > Subject: Re: =~ obsolete?
    >
    >
    > > On Sat, 9 Aug 2003, Dave Brown wrote:
    > >
    > > > In article <>,
    > > > meinrad.recheis <> 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.
    >


    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
    Martin Weber, Aug 9, 2003
    #6
  7. ----- Original Message -----
    From: "Martin Weber" <>
    To: "ruby-talk ML" <>
    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

    --
    Hal Fulton
    Hal E. Fulton, Aug 9, 2003
    #7
  8. Dan Debertin

    Martin Weber Guest

    On Sat, Aug 09, 2003 at 09:26:40AM +0900, Hal E. Fulton wrote:
    > > > 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
    Martin Weber, Aug 9, 2003
    #8
  9. 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 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.

    --
    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
    Florian Frank, Aug 9, 2003
    #9
  10. Dan Debertin

    Martin Weber Guest

    On Sat, Aug 09, 2003 at 09:41:52AM +0900, Florian Frank wrote:
    > 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 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
    Martin Weber, Aug 9, 2003
    #10
  11. 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'.


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

    --
    Do not fear to be eccentric in opinion, for every opinion now accepted was
    once eccentric.
    -- Bertand Russell
    Florian Frank, Aug 9, 2003
    #11
  12. Dan Debertin

    Dave Brown Guest

    In article <Pine.GSO.4.53.0308090058040.8727@neelix>,
    Hugh Sasse Staff Elec Eng <> wrote:
    : On Sat, 9 Aug 2003, Dave Brown wrote:
    :
    : > In article <>,
    : > meinrad.recheis <> 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?"?

    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
    Dave Brown, Aug 9, 2003
    #12
  13. Hi,

    In message "Re: =~ obsolete?"
    on 03/08/09, Hugh Sasse Staff Elec Eng <> writes:

    |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.
    Yukihiro Matsumoto, Aug 9, 2003
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SB

    Did I buy obsolete book?

    SB, Mar 19, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    419
    Jon Skeet [C# MVP]
    Mar 19, 2006
  2. =?Utf-8?B?TmVvIFRoZSBPbmU=?=

    RegisterStartupScript is declared 'obsolete', then what is...

    =?Utf-8?B?TmVvIFRoZSBPbmU=?=, Aug 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,294
  3. newhorizon

    now obsolete

    newhorizon, Nov 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    517
    Steve C. Orr [MVP, MCSD]
    Nov 19, 2005
  4. Replies:
    2
    Views:
    994
    Scott Allen
    Dec 20, 2005
  5. Jeremy Chapman

    OnBindingsCollectionChanged obsolete

    Jeremy Chapman, Feb 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    442
    Jeremy Chapman
    Feb 20, 2006
Loading...

Share This Page