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

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

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

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

    Determine user-selected text

    Jeff S, Jan 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    388
    =?Utf-8?B?VGhvbWFzIEhhIFtNU0ZUXQ==?=
    Jan 23, 2004
  2. Sami Viitanen

    Determine file type (binary or text)

    Sami Viitanen, Aug 13, 2003, in forum: Python
    Replies:
    21
    Views:
    15,595
  3. anonym
    Replies:
    8
    Views:
    1,423
    Arne Vajhøj
    Mar 18, 2008
  4. leo
    Replies:
    1
    Views:
    490
    Bob Lehmann
    Dec 5, 2005
  5. Peña, Botp
    Replies:
    1
    Views:
    479
    Robert Klemme
    Jan 24, 2004
  6. jackster the jackle

    Searching Text for Multiple Matches

    jackster the jackle, Nov 30, 2009, in forum: Ruby
    Replies:
    3
    Views:
    202
    Robert Klemme
    Dec 2, 2009
  7. JK

    Determine value in text box

    JK, Apr 3, 2005, in forum: Javascript
    Replies:
    3
    Views:
    172
    Dr John Stockton
    Apr 5, 2005
  8. Replies:
    1
    Views:
    258
    Thomas 'PointedEars' Lahn
    Jul 10, 2005
Loading...