Perl double-dot range operator .. vs triple-dot ...

perl

Solution

`perlop` says this

If you don't want it to test the right operand until the next evaluation, as in sed, just use three dots ("...") instead of two. In all other regards, "..." behaves just like ".." does.

So with three dots your code won't notice the closing `</title>` if it appears on the same line as the opening tag.

However, the problem is that you are testing for `<title>` in `$line` and `</title>` in `$_`. What you mean is

if ($line =~ /<title>/ .. $line =~ /<\/title>/) { ... }

But please don't do that! You may think it works as it stands but you are clearly running erroneous code already. Regexes are the wrong tool for processing XML: please use `XML::Twig` or `XML::LibXML` instead.

Problem

I am scanning an XML file and loop through each line in the document: ``` while ($line = <$fh>) { if ($line =~ /<title>/.../<\/title>/) { # something... } } ``` I'm unsure what is happening exactly in regards to the `..` and `...` operators. Previously when I used the double dot operator `..` I would receive the error Use of uninitialized value $_ in pattern match (m//) However when I alter the pattern utilizing the triple dot operator `...` the error no longer occurs and the script works as intended. I understand the differences in the operators in general but not in this context. Any help explaining this would be greatly appreciated.

Original source