In article <2E4528861499D41199D200A0C9B15BC031B624@FRISTX>,
 [EMAIL PROTECTED] (Bob Showalter) wrote:

> > -----Original Message-----
> > From: Andre` Niel Cameron [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, November 30, 2001 2:07 PM
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED]
> > Subject: Program dilema
> > 
> > 
> > Hi,
> > 
> > I am having a bit of a problem.  Does anyone have any idea 
> > how I could have
> > a variable and see if the value of that variable is also 
> > located in an array
> > and hash?  IE:
> > 
> > $myvar= 6
> > 
> > @myarray= ("4", "7", 10", 6")
> > 
> > if (6 exists in @myarray) (
> > dothis}
> > else{
> > dothis}
> 
> Your example is for an array. There's a nice FAQ on this:
> 
> perldoc -q 'How can I tell whether a list or array contains a certain
> element?'
> 
> For a hash, use the exists() function:
> 
> perldoc -f exists

The neatest thing I've found for this is Damian Conway's 
Quantum::Superpositions (requires Class::Multimethods also to be 
installed)

#!perl
use warnings;
use strict;
use Quantum::Superpositions;

my @myarray = qw( 10 34 6 87 9 );

print "ok any 'eq 10'\n" if any(@myarray) eq "10";
print "not ok all '< 85'\n" unless all(@myarray) < 85;

This stuff is just brilliant, and makes some things so stupidly simple 
it's like.. magic :)

print pack "H*", "4a75737420416e6f74686572204d61635065726c204861636b65722c0d";
-- 
Scott R. Godin            | e-mail : [EMAIL PROTECTED]
Laughing Dragon Services  |    web : http://www.webdragon.net/
It is not necessary to cc: me via e-mail unless you mean to speak off-group.
I read these via nntp.perl.org, so as to get the stuff OUT of my mailbox. :-)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to