Question

I.e.:

echo H#97llo | MagicPerlCommand

Stdout:

Hallo

were MagicPerlCommand is something like

perl -pnle "s/#(\d+)/chr(\1)/ge"

(but that doesn't work).

Was it helpful?

Solution

Change \1 to $1 in your MagicPerlCommand. The \digit backreference style doesn't t work when the replacement expression is evaluated (i.e. s///e).

That worked for me on Windows and Linux.

OTHER TIPS

As per the j_random_hacker answer, you must use $1 rather than \1.

This is because using the '/e' modifier to the regex means the right hand half is just another normal Perl expression, and not a regex substitution. Since it's Perl, you've got to use Perl's syntax for the bracket reference, and not the usual regex syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top