in reply to How to get variable name in trace message
Perl doesn't make this sort of thing especially easy. Devel::Assert kinda pulls off this trick...
use Devel::Assert -all; my $x = 2; assert($x > 3);
The above will die with the message: Assertion ' $x > 3 ' failed at assert.pl line 5.
How does Devel::Assert do it? With a bit of Devel::Declare magic. Devel::Declare hooks into the Perl compiler, rewriting code before it gets compiled. Using Devel::Declare you could define your own Dumper function which rewrites this:
Dumper($foo)
to this:
Data::Dumper->Dump([$foo], [qw[$foo]])
Not impossible, but probably more effort than it's worth.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get variable name in trace message
by tobyink (Canon) on Jun 15, 2012 at 09:08 UTC | |
by rovf (Priest) on Jun 15, 2012 at 11:00 UTC | |
by SuicideJunkie (Vicar) on Jun 15, 2012 at 15:36 UTC | |
by ChrisBeall (Novice) on Jun 18, 2012 at 02:34 UTC | |
|
Re^2: How to get variable name in trace message
by ChrisBeall (Novice) on Jun 15, 2012 at 06:15 UTC |