Nicholas Clark nick at ccl4.org
Wed Aug 20 23:56:07 BST 2008

Dear lazyweb, er lazylist, er knowledgeable people:

Does a module exist, that can fold constants from expressions as parsed by

I'm a bit of a PPI novice here, but from my brief experiences so far, it
seems that it returns you things like (objects representing)

    '(', '"crash! whap!"', ')'

and it's your job to ascertain that that's actually a constant string. And
$deity help you if the programmer wrote '"crash!" . " " . "whap!"' because
that will be returned as

    '"crash!"', '"."', '" "', '"."', '"whap!"'

and you have to work out that it's syntactically equivalent to a constant string.

So, I was wondering, are there any CPAN modules to take an expression from PPI,
and work out if it is constant? (And if it is, calculate the constant value)

I'm pretty sure that in the general case this is impossible. (for starters,
think floating point rounding on the running platform versus the target
platform, which is a general problem, and then think of a Perl specific
problem that I can overload how "" and '' strings are interpreted, which
*will* affect constant folding)

But assuming that I don't care about the minutiae of floating point, and I'm
running the standard string interpolation rules, is there anybody out there?
Or am I on my own here?

Nicholas Clark

More information about the london.pm mailing list