Loading ...
Sorry, an error occurred while loading the content.

Re: [perlguitest] Re: String comparison | Regular expression .... Urgent

Expand Messages
  • Peter G Martin
    op_boot: ... if ($IP eq ^(10){.}(118){.}(232)* ) # if ($IP eq ^10.118.232.* ) - Didn t work ... You re trying to use a string equivalence comparison (eq)
    Message 1 of 3 , Jul 17 7:08 PM
    • 0 Attachment
      op_boot:
      On Mon, 17 Jul 2006 15:09:36 -0000, you wrote:
      > --- In perlguitest@yahoogroups.com, Girish <girishwill@...>
      > wrote:
      >
      >> Hai Al,
      >>
      >> I need to verify an IP Address: below is my test case ....
      >>
      >> If IP Address = 10.118.232.# -> Pass
      >> If IP Address = 10.118.110.# -> Fail
      >>
      >> Only first 3 values are important, 4 th value can be any
      >> number, i tried the below, but it didn't work, can anyone
      >> tell me the right way to compare the values
      >>
      > ---------------------------------------------------------------
      > ---------------------------------------------------
      >> my $IP = GetWindowText(@wnds[15]);
      if ($IP eq "^(10){.}(118){.}(232)*")
      # if ($IP eq "^10.118.232.*") - Didn't work
      >

      You're trying to use a string equivalence comparison (eq) with a regex ... doesn't work.
      And when you use a regex, the dot "." has a special meaning -- match any character, so
      if you want to match a "." character literally, you have to escape it --- turn it into "\."
      Instead, try something like:

      if($IP =~ m/^10\.118\.232/) # can also take form if($IP =~ /^10\.118\.232/)
      {
      # handle pass
      }
      else
      {
      #handle fail
      }

      You really should read the simple docs supplied with perl on regexes... try: perldoc perlre at the command prompt.

      --Peter M
    Your message has been successfully submitted and would be delivered to recipients shortly.