Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 10th, 2006, 9:31 PM   #1
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
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!
Jessehk is offline   Reply With Quote
Old Mar 10th, 2006, 9:51 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Mar 10th, 2006, 10:06 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
http://perldoc.perl.org/perlfaq4.htm...st-or-array%3f

Exactly what you said. Thanks IR.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Mar 31st, 2006, 6:00 PM   #4
LudakoT
Newbie
 
Join Date: Mar 2006
Location: Macedonia
Posts: 12
Rep Power: 0 LudakoT is on a distinguished road
Of course you can use something dirty like
my @a = qw/1 2 3 4/;
my $var = 2;
if("@a" =~ $var) {
	print "true\n";
}
LudakoT is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC