Perl operator with two points. Vs triple-dot ...

I am viewing an XML file and viewing every line in the document:

while ($line = <$fh>) {
    if ($line =~ /<title>/.../<\/title>/) {
        # something...
    }
}

I’m not sure what exactly happens with ..and .... Previously, when I used the double point operator .., I would get an error

Using the uninitialized value of $ _ according to the pattern (m //)

However, when I modify the template using the triple-point operator ..., the error no longer occurs, and the script works as intended.

I understand the differences in operators in general, but not in this context.

Any help explaining this would be greatly appreciated.

+5
source share
2 answers

perlop talks about it

, , sed, ( "..." ) . "..." , "..".

, </title>, , .

, <title> $line </title> $_.

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

, , ! , , , . Regexes - XML: XML::Twig XML::LibXML .

+11

:

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

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

which means that the right side of the range operator is trying to match with $_instead $line.

+4
source

All Articles