in reply to Disambuating $ in (especially /m) regexps

There's also the option of using /x, having a space after the $ will remove the ambiguity for the compiler and anyone reading the code.

  • Comment on Re: Disambuating $ in (especially /m) regexps

Replies are listed 'Best First'.
Re^2: Disambuating $ in (especially /m) regexps
by tlhackque (Beadle) on Jan 05, 2016 at 12:56 UTC
    I like that unconventional use of /x. Thanks.
      You must be careful not to match lines that are not consecutive.
      use strict; use warnings; my $string = "foo LAST\n" ." blftz\n" ."LINE fum\n" ; print "MATCH\n" if ($string =~ m/LAST$ .* ^LINE/xms) ;

      You could solve this with:

      print "MATCH\n" if ($string =~ m/LAST$ ..? ^LINE/xms) ;
      Bill