Re: question in list

2002-04-17 Thread John W. Krahn

Alex Cheung Tin Ka wrote:
> 
> From: "John W. Krahn" <[EMAIL PROTECTED]>
> 
> > Alex Cheung Tin Ka wrote:
> > >
> > > I have a problem about the list value.
> > > I have got a scalar say $a='a' and a list say @b = ('a', 'b','c');
> > > how can I check whether $a is one of the value in @b. Is there any
> > > easy way to do it and I got lost in perl.com's piles of documentation.
> >
> > if ( grep $a eq $_, @b ) { ... }
> >
> > use Quantum::Superpositions;
> > if ( $a eq any( @b ) { ...  }
> 
> what is the difference with this?
> grep(/$a/, @b);
> &
> grep $a eq $_, @b;


$ perl -e'
$a = q/d/; @b = qw/a b c d e f zzdzz g/;
grep /$a/ && print( "regex: $_\n" ), @b;
grep $a eq $_ && print( "equate: $_\n" ), @b;
'
regex: d
regex: zzdzz
equate: d



John
-- 
use Perl;
program
fulfillment

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




Re: question in list

2002-04-17 Thread Alex Cheung Tin Ka

what is the difference with this?
grep(/$a/, @b);
&
grep $a eq $_, @b; 

perl is amazing


- Original Message - 
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 18, 2002 10:39 AM
Subject: Re: question in list


> Alex Cheung Tin Ka wrote:
> > 
> > I have a problem about the list value.
> > I have got a scalar say $a='a' and a list say @b = ('a', 'b','c');
> > how can I check whether $a is one of the value in @b. Is there any
> > easy way to do it and I got lost in perl.com's piles of documentation.
> 
> 
> if ( grep $a eq $_, @b ) { ... }
> 
> 
> use Quantum::Superpositions;
> if ( $a eq any( @b ) { ...  }
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


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




Re: question in list

2002-04-17 Thread John W. Krahn

Alex Cheung Tin Ka wrote:
> 
> I have a problem about the list value.
> I have got a scalar say $a='a' and a list say @b = ('a', 'b','c');
> how can I check whether $a is one of the value in @b. Is there any
> easy way to do it and I got lost in perl.com's piles of documentation.


if ( grep $a eq $_, @b ) { ... }


use Quantum::Superpositions;
if ( $a eq any( @b ) { ...  }


John
-- 
use Perl;
program
fulfillment

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




RE: question in list

2002-04-17 Thread Timothy Johnson


Here are two ways:

$a = 'a';
@b = qw(a b c);
#
#(1)#Iterate till found
foreach(@b){
   if($a eq $_){
  print "Found it!\n";
   }
}

#
#(2)#Use a hash

foreach(@b){
   $c{$_} = 1;
}

if($c{$a}){
   print "\$a is in there.\n";
}else{
   print "No it's not.\n";
}

-Original Message-
From: Alex Cheung Tin Ka [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 17, 2002 7:27 PM
To: [EMAIL PROTECTED]
Subject: question in list


Dear All,
I have a problem about the list value. 
I have got a scalar say $a='a' and a list say @b = ('a', 'b','c');
how can I check whether $a is one of the value in @b. Is there any easy
way to do it and I got lost in perl.com's piles of documentation.

Thanks
Alex

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




question in list

2002-04-17 Thread Alex Cheung Tin Ka

Dear All,
I have a problem about the list value. 
I have got a scalar say $a='a' and a list say @b = ('a', 'b','c');
how can I check whether $a is one of the value in @b. Is there any easy way to do 
it and I got lost in perl.com's piles of documentation.

Thanks
Alex