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

You don't show us how using a global hash fails for you, but here is an approach:

use strict; use vars qw(%IsMember); %IsMember = ('age' => 1, 'old' => 1, 'years' => 1);

Use it as:

if ($IsMember{age}) { print "'age' is a member\n" }; if ($IsMember{ego}) { print "'ego' is a member\n" };

For development, you can lock the hash keys by using Tie::Hash::FixedKeys.

Replies are listed 'Best First'.
Re^2: Fastest way to test membership in a constant set
by jettero (Monsignor) on Jul 26, 2007 at 15:48 UTC
    Why "use vars qw(%IsMember)" instead of my %IsMember or our %IsMember?

    -Paul

      Because usually, having a global lexical variable is just bad when you need to go around and change it and our basically is a misfeature in my opinion - it doesn't work on 5.005 should the code need to be used on that platform and it doesn't offer any advantage over use vars().