in reply to Parsing Issue while using Variable name in Pattern

"\b" Expects a transition between a "\w" and a \W", so it will not match the transition between the ")" and ")" in your "machine30" case.

If you know there is something that is not a "Word" character, immediately following the machine name, you can use:

m/\Q$machine\E\W/
to match all your cases.

            “PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.”
        ― Jon Ribbens

Replies are listed 'Best First'.
Re^2: Parsing Issue while using Variable name in Pattern
by perlavi (Initiate) on Feb 16, 2012 at 05:26 UTC

    Hi NetWallah,
    Using \W worked perfectly fine. But I could not get the difference between \b and \W even though I was able to partially resolve the issue using \b. Using \b only worked for common strings in a machine name but not for machine names with special characters.

      From http://perldoc.perl.org/perlre.html#Regular-Expressions :
      \b Match a word boundary

      A word boundary (\b ) is a spot between two characters that has a \w on one side of it and a \W on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a \W .

      So, the "\b" will match "xxyy" if the following character is NOT [a-zA-Z0-9].

      However, if the terminating character in the match is NOT a "word" character, as in your case - the terminating character is ")", then the "\b" expects the NEXT character to be a "word".

      Hope this makes sense. If not, please experiment.

                  “PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.”
              ― Jon Ribbens