mrbark has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I upgraded from perl 5.16 to 5.22.
I have hundreds of scripts that I just cannot modify.

This now fails:

perl -e 'my $var = "hello"; $var =~ s!(?<=\D[01] file)s!!ig;'

It seems that the i option produces the variable length failure because of unicode processing of regexps.

So my question is:
Without modifying this part of code, what can I do to get the same normal behavior I had with 5.16, without downgrading back to 5.16?
I can recompile 5.22 w/ different options if needed.

Thank you!

Replies are listed 'Best First'.
Re: Lookbehind issues with unicode
by choroba (Cardinal) on Jul 21, 2015 at 16:33 UTC
    The problem lies in the word "file", where "fi" can be represented by a ligature. Adding single /a doesn't help, but /aa solves the problem. So, if you don't work with unicode, you can just run your scripts like
    perl -Mre=/aa -e 'my $var = "hello"; $var =~ s!(?<=\D[01] file)s!!ig;'
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Unbelievable :) I would have never thought about that one! Thank you so much.
      Then there is less code to modify than I thought so I can probably modify these very specific regexps.
Re: Lookbehind issues with unicode
by ikegami (Patriarch) on Jul 21, 2015 at 21:43 UTC

    Best to avoid the needless, troublesome, expensive lookbehind by replacing (?<=FOO)BAR with FOO\KBAR.

    perl -e 'my $var = "hello"; $var =~ s!\D[01] file\Ks!!ig;'

    Requires 5.10+