in reply to Re: Fun with Prototypes
in thread Fun with Prototypes

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

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!