in reply to Named array indices

I've used the constant pragma to address this problem. I believe that it actually resolves at Compile time and get away from repeated subroutine calls at Run time. (But I may be remembering wrong, the library in my local Coffee shop is woefully lacking in Perl material. Maybe I ought to fix that....)
#! /usr/local/bin/perl use strict; use warnings; use constant AAA=>1; use constant BBB=>0; my @this_array; $this_array(AAA) = 'Scrumtidlyumptions'; $this_array(BBB) = 'Cupcakes taste'; print(join(' ',@this_array), "\n");
Coded but not run.

----
I Go Back to Sleep, Now.

OGB

Replies are listed 'Best First'.
Re^2: Named array indices
by LanX (Saint) on Aug 05, 2010 at 17:26 UTC
    AFAIK this is basically the same approach.

    The constant pragma just produces the inlinedı subs I used.

    IMHO the namespaces of constants and subs collide.

    Cheers Rolf

    1) like sub AAA(){1} , i.e. empty prototype and ending with value evaluable at compile-time.

      Constants are a bit more memory efficient and easier to read.
        I found another difference, it's possible to pass array-refs with use constants. :)

         sub AR () {[]} doesn't work!

        Cheers Rolf