How to determine of text matches?

Discussion in 'Perl' started by nospam, Aug 22, 2004.

  1. nospam

    nospam Guest

    In the code fragment below, I'm doing a substitution
    of the key/value pairs in a hash using s/$key/$value/g;.
    How can I determine if a match is found? I want to do
    something like:

    If (match found) {
    print "FOUND MATCH";
    }

    -Thanks


    #############################

    return unless -T;

    print "Processing==> $File::Find::name\n";

    my $obj = tie(my @array, 'Tie::File', $_) || die "$!\n";

    for (@array) {

    while ((my $key, my $value) = each %strings) {

    s/$key/$value/g;

    }

    }

    untie @array;
    nospam, Aug 22, 2004
    #1
    1. Advertising

  2. nospam

    Joe Smith Guest

    nospam wrote:

    > How can I determine if a match is found?


    It's simple. Just test whether s/// returned true or not.

    > If (match found) {
    > print "FOUND MATCH";
    > }


    if (s/$key/$value/g){
    print "FOUND MATCH";
    }

    Any textbook that does not mention that should be thrown in the garbage.
    -Joe
    Joe Smith, Aug 22, 2004
    #2
    1. Advertising

  3. nospam

    Guest

    nospam <> wrote in message news:<>...
    > In the code fragment below, I'm doing a substitution
    > of the key/value pairs in a hash using s/$key/$value/g;.
    > How can I determine if a match is found?


    You appear to have a question about the behaviour of s///g. Have you
    considered looking up the explaination of the behaviour of s/// in the
    Perl reference documentation?

    > I want to do something like:
    >
    > If (match found) {
    > print "FOUND MATCH";
    > }


    if ( s/$key/$value/g ) {
    print "FOUND MATCH";
    }

    This newsgroup does not exist (see FAQ). Please do not start threads
    here.
    , Aug 22, 2004
    #3
    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. Boris Pelakh
    Replies:
    3
    Views:
    455
    Purl Gurl
    Apr 8, 2004
  2. Doug
    Replies:
    0
    Views:
    458
  3. Stephan Bour

    Extracting matches from Regex.Split

    Stephan Bour, Oct 29, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,511
    Stephan Bour
    Oct 30, 2003
  4. Peña, Botp
    Replies:
    1
    Views:
    221
    Robert Klemme
    Jan 24, 2004
  5. jackster the jackle

    Searching Text for Multiple Matches

    jackster the jackle, Nov 30, 2009, in forum: Ruby
    Replies:
    3
    Views:
    102
    Robert Klemme
    Dec 2, 2009
Loading...

Share This Page