DEV Community

Discussion on: Blog post: Perl's Constant Pragma and Readonly Module

Collapse
willt profile image
William Taylor

Nice post. Here is Const::Fast

 # cat const_fast_optimization.pl 
#!/usr/bin/env perl

use strict;
use warnings;
use v5.10;
use Const::Fast;

const my $DEBUG => 1;

if ($DEBUG) {
    print STDERR "Hello Happy World of Debugging\n";
}

exit 0;
# perl -MO=Terse const_fast_optimization.pl 
LISTOP (0x9313d0) leave [1] 
    OP (0x79eb20) enter 
    COP (0x931070) nextstate 
    UNOP (0x931530) entersub [3] 
        UNOP (0x923d90) null [148] 
            OP (0x8baba0) pushmark 
            UNOP (0x931390) srefgen 
                UNOP (0x931440) null [148] 
                    OP (0x8bab00) padsv [2] 
            SVOP (0x8ba9e0) const [7] IV (0x921cb0) 1 
            UNOP (0x99fb80) null [17] 
                PADOP (0x92b6d0) gv  GV (0x92fbe8) *const 
    COP (0x923c60) nextstate 
    UNOP (0x931120) null 
        LOGOP (0x931290) and 
            OP (0x930f60) padsv [2] 
            LISTOP (0x931310) scope 
                OP (0x923b50) null [183] 
                LISTOP (0x931180) print 
                    OP (0x9314b0) pushmark 
                    UNOP (0x9311e0) rv2gv 
                        PADOP (0x9312d0) gv  GV (0x7a4768) *STDERR 
                    SVOP (0x931220) const [8] PV (0x921c80) "Hello Happy World of Debugging\n" 
    COP (0x923d00) nextstate 
    UNOP (0x930fc0) exit 
        SVOP (0x931000) const [9] IV (0x921bf0) 0 
const_fast_optimization.pl syntax OK
Collapse
jonasbn profile image
jonasbn Author

Thanks for the example :-)

Any conclusions on your behalf?