On Sep 29, 12:18*pm, "John W. Krahn" <jwkr...@example.com> wrote:
> Akim Demaille wrote:
>
> > The following does not work. *This was expected, but since pre is
> > sometimes surprisingly powerful, I meant to make sure. *The idea is to
> > handle with the s operator strings of x's preceded by their number
> > (and for instance to replace them with X). *For instance "{2}xxx"
> > should give "XXx". *So I tried this:
>
> > echo "{2}xxx" | perl -p -e 's/\{(\d+)\}x{\1}/"X" x $1/ge
>
> $ echo "{2}xxx" | perl -p -e 's/\{(\d+)\}(x+)/substr $a = $2, 0, $1, "X"
> x $1; $a /ge'
> XXx
Thanks for this. I have to add a check to make sure that we don't
overrun the available space (see for instance:
$ echo "{4}xx" | perl -p -e 's/\{(\d+)\}(x+)/substr $a = $2, 0, $1,
"X" x $1; $a /ge'
XXXX
)
I know I can do that, no problem. But still, I am really curious to
know what Perl understood here, since it did not complain about this
weird arity argument.
|