in reply to [SOLVED] Get element count of CONSTANT list (aref))

#!/usr/bin/perl # http://perlmonks.org/?node_id=1210767 use strict; use warnings; use constant STEPPER_SEQUENCE => [ [qw(1 0 0 1)], [qw(1 0 0 0)], [qw(1 1 0 0)], [qw(0 1 0 0)], [qw(0 1 1 0)], [qw(0 0 1 0)], [qw(0 0 1 1)], [qw(0 0 0 1)], ]; print STEPPER_SEQUENCE->@* . "\n";

Replies are listed 'Best First'.
Re^2: Get element count of CONSTANT list (aref))
by stevieb (Canon) on Mar 12, 2018 at 22:22 UTC

    ++ tybalt89, I had thought about and actually tested that as well, but I can't use that. If I used postfix-deref, then that would force the encompassing distribution (or other consumers) to require 5.20 at minimum, which I refuse to go above 5.10.

    Besides, it results in the same type of behaviour:

    use warnings; use strict; use feature 'say'; use constant STEPPER_SEQUENCE => [ [qw(1 0 0 1)], [qw(1 0 0 0)], [qw(1 1 0 0)], [qw(0 1 0 0)], [qw(0 1 1 0)], [qw(0 0 1 0)], [qw(0 0 1 1)], [qw(0 0 0 1)], ]; use constant STEP_COUNT => STEPPER_SEQUENCE->@*; say STEP_COUNT;

    Output:

    ARRAY(0x17985b8)ARRAY(0x17981f8)ARRAY(0x17c8e68)ARRAY(0x17edc90)ARRAY( +0x17edd80)ARRAY(0x17a7708)ARRAY(0x17ee0c8)ARRAY(0x1805590)
      Besides, it results in the same type of behaviour:

      In list context, yes, but like @{...} you can force it to scalar context: 0+STEPPER_SEQUENCE->@* is 8. And BTW, there is also STEPPER_SEQUENCE->$#* which will returns 7. tybalt89's code forced the scalar context with the dot . operator.