![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
Perl "in" operator (or something similar?)
I'm just starting to look at Perl, and so far, I (surprisingly) quite like it.
I have enjoyed the python in operator before eg: >>> 1 in [1, 2, 3] => True Is there a similar function in Perl? (I do know of the documentation, but I'm still sort of working my way through it). Thanks ![]()
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
You could use a hash... the keyword to use is "exists".
May want to create a function to return true or false, etc... There may be a more optimal solution to this. %pass = (1,2,3);
if (exists $pass{9})
{
print "True\n"
}
else
{
print "False\n"
}
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS! |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2006
Location: Macedonia
Posts: 12
Rep Power: 0
![]() |
Of course you can use something dirty like
my @a = qw/1 2 3 4/;
my $var = 2;
if("@a" =~ $var) {
print "true\n";
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|