in reply to Re: using constants in regex/search
in thread using constants in regex/search

You can use like this
if ($input =~ /${\NAME}/) { print "Matched!"; }

Replies are listed 'Best First'.
Re^3: using constants in regex/search
by JavaFan (Canon) on Dec 02, 2008 at 11:43 UTC
    That's identical to
    if ($input =~ /$NAME/) {...}
    which is what I used, so I don't get your point.
      You have copied the NAME value to a variable and used as $NAME.
      i have specified a method, which will use the constant NAME itself in the regular expression
      use strict; use constant NAME => 'abc'; if ($ARGV[0] =~ /${\NAME}/) { print "match"; };
        You're sure you didn't update your post? I know about the difference between ${NAME} and ${\NAME}, and when replying, I checked to make sure there wasn't a \ there.
      You're thinking of ${NAME}. ${\NAME} is the scalar version of @{[ NAME ]}.