in reply to Multi-dimensional constants

sub { "DUMMY" };
I was under the impression that constants are really subs that I could take the reference of
They are, and you can, but Data::Dumper seems to be having problems deparsing subroutines created by use constant back into source code. You have to set $Data::Dumper::Deparse to a true value to make Data::Dumper use B::Deparse, but even then the constant is nowhere to be seen, despite the subroutine itself works:
use strict; use warnings; use Data::Dumper; local $Data::Dumper::Deparse = 1; use constant INVALID_DATA => ( q{invalid}, 0 ); use constant ADD_DATA => ( q{add}, 1 ); use constant REMOVE_DATA => ( q{remove}, 2 ); use constant MODES => ( \&ADD_DATA, \&REMOVE_DATA ); print Dumper [ MODES ]; print Dumper [ (MODES)[0]() ];

Replies are listed 'Best First'.
Re^2: Multi-dimensional constants
by AnomalousMonk (Archbishop) on Nov 22, 2020 at 16:42 UTC
    print Dumper [ (MODES)[0]() ];

    This statement compiles and runs as expected under Perl version 5.30.3.1 64-bit, but fails to compile under version 5.8.9.5 32-bit (both Strawberry). In the latter case, either of
        print Dumper [ (MODES)[0]->() ];
        print Dumper [ &{ (MODES)[0] } ];
    will work. I haven't done a binary search to find the version at which the quoted syntax begins to be supported (assuming, of course, that the root cause of the failure is a syntax enhancement).


    Give a man a fish:  <%-{-{-{-<