How to determine of text matches?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nospam

    How to determine of text matches?

    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::na me\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;


  • Joe Smith

    #2
    Re: How to determine of text matches?

    nospam wrote:
    [color=blue]
    > How can I determine if a match is found?[/color]

    It's simple. Just test whether s/// returned true or not.
    [color=blue]
    > If (match found) {
    > print "FOUND MATCH";
    > }[/color]

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

    Any textbook that does not mention that should be thrown in the garbage.
    -Joe

    Comment

    • nobull@mail.com

      #3
      Re: How to determine of text matches?

      nospam <no@spam.com> wrote in message news:<pan.2004. 08.21.23.17.04. 502090@spam.com >...[color=blue]
      > 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?[/color]

      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?
      [color=blue]
      > I want to do something like:
      >
      > If (match found) {
      > print "FOUND MATCH";
      > }[/color]

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

      This newsgroup does not exist (see FAQ). Please do not start threads
      here.

      Comment

      Working...