Perl can regularly surprise you with many ways of doing the same thing. I’d seen the following fragment of a script and thought “how can that work … there’s no match operator”.
if ( $CC =~ "xlC|xlc" )
{
# stuff.
}
What I’d expected is a match // operator, or one that used explicit delimiters such as m@@, as in one of:
if ( $CC =~ /xlC|xlc/ )
{
# stuff.
}
# or
if ( $CC =~ m@xlC|xlc@ )
{
# stuff.
}
I’d had the urge to “correct” this incorrect if condition, but a small experiment confirms that this code actually worked as intended:
$CC = "/blah/xlC" ;
#$CC = "/blah/gcc" ;
if ( $CC =~ "xlC|xlc" )
{
print "m\n" ;
}
No explicit match delimited expression is required. It appears that the context of the binding operator is enough to convert a subsequent string into a regular expression. I think I still like doing it explicitly better, perhaps just since that’s how I’ve seen it done the most.