I guess the tag is a variable, and it is checking for 9eaf
- but does this exist in Perl?
What is the "=~" sign doing here and what are the "/" characters before and after 9eaf
doing?
if ($tag =~ /9eaf/) { # Do something }
=~ is the Perl binding operator. It's generally used to apply a regular expression to a string; for instance, to test if a string matches a pattern: if ($string =~ m/pattern/) {
$1 equals the text " brown ".
From the Perl Doc. $/ and $\ which are the input and output record separators respectively. They control what defines a "record" when you are reading or writing data. By default, the separator used is \n .
=~
is the operator testing a regular expression match. The expression /9eaf/
is a regular expression (the slashes //
are delimiters, the 9eaf
is the actual regular expression). In words, the test is saying "If the variable $tag matches the regular expression /9eaf/ ..." and this match occurs if the string stored in $tag
contains those characters 9eaf
consecutively, in order, at any point. So this will be true for the strings
9eaf xyz9eaf 9eafxyz xyz9eafxyz
and many others, but not the strings
9eaxxx 9xexaxfx
and many others. Look up the 'perlre' man page for more information on regular expressions, or google "perl regular expression".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With