parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Change behaviour of {= perlexpr =}


From: Ole Tange
Subject: Change behaviour of {= perlexpr =}
Date: Wed, 17 Feb 2021 12:54:51 +0100

The places where you can use a replacement string you can also use a
replacement string with perl code.

In fact, all replacement strings are defined using perl:

        '{/.}' => 's:.*/::; s:\.[^/.]+$::;',
        '{#}'  => '1 $_=$job->seq()',

So far this code has been pure perl (possibly prepended with the input
source number).

Today you can write:

  {= if($arg[1] < $arg[2}) { skip() } =}

I am considering changing it, so you can also use replacement strings
in the perl code:

  {= if( {1} < {2} ) { skip() } =}

There are some issues with that:

1. Pure perl code can contain strings that looks like replacement strings:

  s/a{3}/b/

This means match 'aaa'. But if I implement the above, then {3} will be
replaced with $arg[3].

In my time of writing perl, it is quite rare, that I use the above
construct, and it is easy to change it to something that does the
same, but which does not match a replacement string:

  s/a{3,3}/b/

2. It can lead to infinite recursion, if the user defines replacement
strings like:

  {foo} => {= {bar} > 3 =}
  {bar} => {= {foo} > 3 =}

I can mitigate this by simply not allowing any recursion. It will be
easier to implement and faster, but it may be surprising that you
cannot use replacement strings in replacement strings in replacement
strings.

What do you think?

/Ole



reply via email to

[Prev in Thread] Current Thread [Next in Thread]