| [reply] |
Thanks for the comments, and I did think about it - but I think I want to keep the "trick question" aspect of the node for now ;-)
Also thank you for your other replies, that's certainly getting pretty tricky with the parsing!
| [reply] |
More fun for you: ;)
Some people want debug functions to disappear without footprint in production.
Like with Smart::Comments but without source filter.
Try to find a way where changing the prototype of a function &dmp will turn the call to a no op.
Your bar /#(\w+)/, @a; is already quite close, but it's still involving a division. :)
| [reply] [d/l] [select] |
use constant DEBUG => 0;
use Data::Dumper;
# ...
warn Dumper($myvar) if DEBUG;
Or PerX::Assert. | [reply] [d/l] |
| [reply] [d/l] |
an example avoiding a sub-call, unfortunately the division in void context is not optimized away.
use warnings;
use strict;
use B::Deparse;
use Data::Dump;
use constant DEBUG =>1;
BEGIN {
unless (DEBUG) {
*dmp = sub() {
1;
}
} else {
*dmp = sub($;@){
shift;
dd \@_;
}
}
}
sub test {
#$_="#";
my @a=1..3;
dmp/#/,
@a;
}
test();
warn "DEBUG = ",DEBUG,"\n";
print B::Deparse->new()->coderef2text(\&test);
OUTPUT
DEBUG = 0
{
use warnings;
use strict;
my(@a) = 1..3;
1 / @a;
}
Use of uninitialized value $_ in pattern match (m//) at ... line 27.
DEBUG = 1
[1, 2, 3]
{
use warnings;
use strict;
my(@a) = 1..3;
dmp /#/, @a;
}
and the warning will create runtime overhead, too :/
update
But I think a little overhead is acceptable when debugging.
another edge case are empty arrays causing a division by zero...
update:
fixed minor bug
| [reply] [d/l] [select] |
I don't quite understand what you're after, but you can check this module: B::Deparse
Update: Sorry haukex, the spoilers did not work when I first tried to click on them. Now that I can see them, I understand your point. | [reply] |