in reply to Re: Pattern match
in thread Pattern match

Following is a sample code: if ($_ =~ m/received 486 response to blah/){ do this; } else{ do that; } However this doesn't seem to work correctly, because when a portion of the string is "received 480 response to blah" it still matches and breaks the logic.

Replies are listed 'Best First'.
Re^3: Pattern match
by Eily (Monsignor) on Dec 05, 2014 at 08:30 UTC

    when a portion of the string is "received 480 response to blah" it still matches
    Your regex does not match 'received 480 response to blah', so either your error is somewhere else in your code, or as stated by GrandFather, your string $_ contains both the 486 and 480 variations.

    When we say "runnable code", we mean something that we can copy and run, and that will actually do something. If I run: perl -e 'if ($_ =~ m/received 486 response to blah/){ do this; } else{ do that; }' nothing happens.