in reply to dynamic perl code inside my perl program

For dynamic code you want eval. That's one of its most common duties.

However, your example doesn't really demonstrate a real need for dynamic code. If all you want is a function that returns one thing, or another depending on the outcome of a comparison, you can just use simple program logic with if statements or the ?: trinary operator.

You may even consider double-barreled-closures as a means of returning a subref to one of several subs depending on the outcome of the logic test.

But eval is always a sure bet for dynamic code.


Dave


"If I had my life to do over again, I'd be a plumber." -- Albert Einstein