Ratazong has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I want to check if a value is inside a set of predefined values. Which is the best way to do so? I came to the following solution, but somehow I have the feeling there must be a more elegant way...
Rata (failing to google it himself)my $var = "apple"; if (exists( { banana => 1, plum => 1, apple => 1, strawberry => 1, pea + => 1,}->{$var} )) { print "yes!\n"; } else { print "no.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: check if a value is in a given set
by choroba (Cardinal) on Jul 24, 2012 at 15:34 UTC | |
|
Re: check if a value is in a given set
by Anonymous Monk on Jul 24, 2012 at 15:33 UTC | |
|
Re: check if a value is in a given set
by hippo (Archbishop) on Jul 24, 2012 at 16:21 UTC | |
|
Re: check if a value is in a given set
by brx (Pilgrim) on Jul 24, 2012 at 15:40 UTC | |
|
Re: check if a value is in a given set
by Marshall (Canon) on Jul 25, 2012 at 03:48 UTC | |
|
Re: check if a value is in a given set
by 2teez (Vicar) on Jul 24, 2012 at 15:51 UTC | |
by Anonymous Monk on Jul 24, 2012 at 17:45 UTC |