Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Get element count of CONSTANT list (aref))

by tybalt89 (Priest)
on Mar 12, 2018 at 22:17 UTC ( #1210773=note: print w/replies, xml ) Need Help??


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 (Abbot) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1210773]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-04-20 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?