in reply to Re^2: regex switch trouble
in thread regex switch trouble

When you put executable perl code into the replacement (right-hand) portion of  s///e, I think you are by nature using "eval" to execute that code. Therefore, you run up against this little detail described in the man page for Switch (under the section heading "LIMITATIONS"):
Due to the way source filters work in Perl, you can't use Switch inside a string "eval".
The reference to "source filters" there has to do with how the Switch module is implemented. When you use it, the code that ends up being executed is actually different in significant ways from the code that you wrote. That's why many people (including the author of the module) advise against using Switch in "production code" (i.e. for anything that needs to be rock-solid and readily maintainable).

As GrandFather pointed out, there are better ways to do what you need to do in this case.

Replies are listed 'Best First'.
Re^4: regex switch trouble
by blazar (Canon) on Jun 24, 2007 at 10:04 UTC
    When you put executable perl code into the replacement (right-hand) portion of s///e , I think you are by nature using "eval" to execute that code.

    Nope, that's /ee, which in fact is discouraged and rarely used nowadays, that I can see. /e is not associated with the same issues. Thinking of all these matters, however, one can only appreciate even more how good they are doing with the new rules.

      Well, okay, thanks... I really don't enough about the perl internals involved with this operator to assert otherwise, and I'll admit I was "guessing" about this (hence the hedging phrase "...I think...")

      Still, perlop does describe the "e" modifier in s///e as: "Evaluate the right side as an expression", and I have to wonder whether this kind of evaluation (whatever kind it is) may have enough in common with "string eval" to have a similar effect on source filters and the Switch module. Based on evidence in the thread, it apparently does.

      Thanks for the pointer to the "Apocalypse" pages.

        Still, perlop does describe the "e" modifier in s///e as: "Evaluate the right side as an expression", and I have to wonder whether this kind of evaluation (whatever kind it is) may have enough in common with "string eval" to have a similar effect on source filters and the Switch module. Based on evidence in the thread, it apparently does.

        I think (too!) it merely makes or can make a hell to "parse", the rationale being, in any case, that one can happily use /e without feeling guilty but should do so if tempted to use /ee too.