in reply to reinterpolation of regexp (and strings?)

Tricky. I don't think you can do it without the eval. Unless the /ee option does the trick as ikegami suggests.

I ran into a similar problem and had to use eval. I am very much interested if there is another way of doing this. Your suggestion of re-interpolation sounds nice but is probably very tricky to implement.

  • Comment on Re: reinterpolation of regexp (and strings?)

Replies are listed 'Best First'.
Re^2: reinterpolation of regexp (and strings?)
by ikegami (Patriarch) on Jul 23, 2008 at 08:21 UTC

    Tricky. I don't think you can do it without the eval. Unless the /ee option does the trick as ikegami suggests.

    s/.../.../ee is short for s/.../eval .../e, so that "unless" is not an exception.

    Your suggestion of re-interpolation sounds nice but is probably very tricky to implement.

    It's not possible since interpolation involved executing arbitrary code. Maybe a limited form of interpolation? That would be possible and useful.

      Are you aware that _any_ string interpolation can inject _any_ arbitrary code in a string? Try this:
      perl -le 'print qq(@{[ do{ print q(I got here first); 1 } ]})'
      The thing is: there is no safe string interpolation, you you might as well do the //ee thingy. :-)
      []s, HTH, Massa (κς,πμ,πλ)

        Are you aware that _any_ string interpolation can inject _any_ arbitrary code in a string?

        Yes, I know since I said as much in the post to which you replied.

        Are you aware that _any_ string interpolation can inject _any_ arbitrary code in a string?

        Not true. The one provided by String::Interpolate doesn't.

        The native interpolation mechanism does, but we were never talking about that. The OP was proposing a new feature. While I don't see anyone putting in the effort into implementing what is really just another template system, I mentioned that interpolation is not necessarily unsafe, only the current native implementation, and that a safe implementation could be devised.

Re^2: reinterpolation of regexp (and strings?)
by AlwaysLearning (Sexton) on Jul 23, 2008 at 08:42 UTC
    I'm not sure of the overhead involved in String::Interpolate, but it sure is easy to code and use. And lots of options for different types of interpolation, which makes me wonder if there is more overhead than needed....

    a qi{} operator could probably handle the simple case of interpolation without overhead, except on the part of the porters to code it...