in reply to pattern matching once

Change:

if ( $line =~ m/<FILENAME>.*\.htm/ ) {

To:

if ( $line =~ ?<FILENAME>.*\.htm? ) {
Naked blocks are fun! -- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re^2: pattern matching once
by jo37 (Curate) on Aug 11, 2023 at 09:30 UTC
    if ( $line =~ ?<FILENAME>.*\.htm? ) {

    This should be:

    if ( $line =~ m?<FILENAME>.*\.htm? ) {

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

      perldoc perlop
      
      ...
      
             "m/PATTERN/msixpodualngc"
             "/PATTERN/msixpodualngc"
      
      ...
      
             "m?PATTERN?msixpodualngc"
             "?PATTERN?msixpodualngc"
      
      

      With the // or ?? delimiters the m at the beginning is optional.

      Naked blocks are fun! -- Randal L. Schwartz, Perl hacker
        With the // or ?? delimiters the m at the beginning is optional.

        That was true until about 8 years ago. Now:

        In the past, the leading m in m?PATTERN? was optional, but omitting it would produce a deprecation warning. As of v5.22.0, omitting it produces a syntax error. If you encounter this construct in older code, you can just add m.

        Typo fix

        I guess it's time to switch to a modern Perl?

        That seems to be gone in Perl 5.26, though I failed to spot it in perldelta.