Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^3: var comparison

by Anonymous Monk
on Sep 08, 2012 at 08:57 UTC ( #992452=note: print w/replies, xml ) Need Help??

in reply to Re^2: var comparison
in thread var comparison

If your list of possible values gets long, you could store them as keys of a hash and then check for existence or definedness in the hash.

Replies are listed 'Best First'.
Re^4: var comparison
by nemesisgus (Acolyte) on Sep 08, 2012 at 18:32 UTC

    Yes, that's one of the solutions MidLifeXis proposed and I think it's also considered a Perl "best practice".

      hmm, nobody gave you a code example ?

      DB<100> @option{qw/a b c/}=() => (undef, undef, undef) DB<101> exists $option{a} => 1 #true DB<102> exists $option{d} => "" #false

      but smart-match should be safe as long as you don't forget the quotes.

      Cheers Rolf

        Nice hash slice, thanks!

        Just let me polish up your code so other newbies don't get confused:

        my %option; @option{qw/a b c/}=(); # my %option = ( # 'a' => undef, # 'b' => undef, # 'c' => undef # ); exists $option{a} and print 'true'; exists $option{d} or print 'false';

        PS: what the h**l is DB <...> ?

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-03-19 09:40 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (238 votes). Check out past polls.