in reply to printing variable and evaluation

I suppose you could write a source filter that scans the code at BEGIN time and replaces every instance of Pprint($variable) with something like print("\$variable returns $variable");, but it sounds like a recipe for disaster. It would be very fragile, bound to break at every imaginable edge case.

I'd take a step back and think about what you actually want to achieve. In the end, you want to see in your output not just the value of a variable, but some context (semantic information) for that value as well. The name of the variable is a poor source of that context. It's better to provide it explicitly.

So do something like print("setting foo/bar/baz = '$variable'"). The point is to accompany the variable printout with an explanation that makes sense for you in the context of your application (and will make sense in 5 years in the future). You can write a helper function for it if you want.

Replies are listed 'Best First'.
Re^2: printing variable and evaluation
by haukex (Archbishop) on Jul 07, 2017 at 11:42 UTC
    In the end, you want to see in your output not just the value of a variable, but some context (semantic information) for that value as well.

    That's a good point! Data::Dump provides a ddx function that includes the file name and line number from where it was called in the printout.