What does =~ mean in Perl?
55,620
=~
is the Perl binding operator and can be used to determine if a regular expression match occurred (true or false)
$sentence = "The river flows slowly.";
if ($sentence =~ /river/)
{
print "Matched river.\n";
}
else
{
print "Did not match river.\n";
}
Comments
-
Cole Tobin almost 2 years
Possible Duplicate:
What does =~ do in Perl?In a Perl program I am examining (namly plutil.pl), I see a lot of
=~
on the XML parser portion. For example, here is the functionUnfixXMLString
(lines159
to167
on 1.7 ($VERSION
wrongly declared as "1.5")):sub UnfixXMLString { my ($s) = @_; $s =~ s/</</g; $s =~ s/>/>/g; $s =~ s/&/&/g; return $s; }
From what I can tell, its C prototype would be (C-like)
string UnfixXMLString(string s)
, and it uses the=~
operator on the parameter (s
) and then returns the modified string, but what is it doing?