in reply to Fastest way to test membership in a constant set

Okay - it seems like the closure method is the fastest at this time. But, can a use constant be used to define a constant set in Perl 5.6.1?
  • Comment on Re: Fastest way to test membership in a constant set

Replies are listed 'Best First'.
Re^2: Fastest way to test membership in a constant set
by QM (Parson) on Jul 27, 2007 at 19:57 UTC
    constant, example 3.

    See the update here.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of

        Sorry, I saw something that I thought worked:
        use constant { SEC => 0, MIN => 1, HOUR => 2, MDAY => 3, MON => 4, YEAR => 5, WDAY => 6, YDAY => 7, ISDST => 8, };
        Instead, it's just syntax sugar to declare multiple constants with one use constant statement.

        I searched the doc on constant, and didn't see a good example, though

        Dereferencing constant references incorrectly (such as using an array subscript on a constant hash reference, or vice versa) will be trapped at compile time.
        implies that a hash constant can be created.

        Here's how it's done:

        use constant Books_I_Own => { "The Wit and Wisdom of Mark Twain" => 1, "Attack of the Deranged Mutant Killer Monster Snow Goons" => 1, "Unix Power Tools" => 1, }
        and from the debugger
        DB<2> x Books_I_Own 0 HASH(0x1c831b8) 'Attack of the Deranged Mutant Killer Monster Snow Goons' => 1 'The Wit and Wisdom of Mark Twain' => 1 'Unix Power Tools' => 1
        ...so it is possible to have a constant set, if a hash is a set.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of