Perl equivalent of mysql "like"

Discussion in 'Perl' started by Manasa, Jun 3, 2004.

  1. Manasa

    Manasa Guest

    Is there a Perl's equivalent of MySQL "like" operation?

    I have to match names from the database in the same way as MySQL's
    like operation without executing a mysql query.

    I have tried Perl's String::Approx but even that does not completely
    solve my problem.

    This is what I want to do:

    $name = "CIVITAF INCORPORATED";

    And my hash has the following:

    $hash->{"CIVITAF INC OF CALIFORNIA"} = "121212";

    I want to do this

    foreach $key (keys %{$hash}) {

    if ($key like $name) {

    ....
    .....
    }
    }

    Any help would be appreciated.

    Thanks,
    Manasa
     
    Manasa, Jun 3, 2004
    #1
    1. Advertising

  2. Manasa

    Skeleton Man Guest

    >Is there a Perl's equivalent of MySQL "like" operation?

    >I have to match names from the database in the same way as MySQL's
    >like operation without executing a mysql query.


    Use regular expressions. In the most basic form this check if $key contains
    the contents of $name anywhere:
    (Case insensitive)

    if ($key =~ /$name/i) {
    ...
    ...
    }


    Regards,
    Chris
     
    Skeleton Man, Jun 4, 2004
    #2
    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. Ravi
    Replies:
    6
    Views:
    1,410
    Suchandra Thapa
    Jul 21, 2003
  2. Patrick Kowalzick
    Replies:
    5
    Views:
    477
    Patrick Kowalzick
    Mar 14, 2006
  3. Replies:
    3
    Views:
    161
    Tad McClellan
    Apr 28, 2006
  4. Davy
    Replies:
    2
    Views:
    141
  5. Morten Guldager
    Replies:
    0
    Views:
    122
    Morten Guldager
    Jan 8, 2013
Loading...

Share This Page