RE: newbie - in

2002-09-27 Thread Timothy Johnson


check out "perldoc -f grep"

-Original Message-
From: Kyle Babich [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 27, 2002 4:34 AM
To: beginners
Subject: newbie - in


Does Perl have an in operator or something similar?
If not how would I find out if a certain list has a certain element?

Thank you,
--
Kyle

-- 
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: newbie - in

2002-09-27 Thread Sudarshan Raghavan

On Fri, 27 Sep 2002, Kyle Babich wrote:

> Does Perl have an in operator or something similar?
> If not how would I find out if a certain list has a certain element?

Read through
perldoc -q 'How can I tell whether a certain element is contained in a list or array?'




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




RE: newbie - in

2002-09-27 Thread Sudarshan Raghavan

On Fri, 27 Sep 2002, Timothy Johnson wrote:

> 
> check out "perldoc -f grep"

grep should not be used for this purpose, it will run through the entire 
list even after the desired element has been found.

> 
> -Original Message-
> From: Kyle Babich [mailto:[EMAIL PROTECTED]]
> Sent: Friday, September 27, 2002 4:34 AM
> To: beginners
> Subject: newbie - in
> 
> 
> Does Perl have an in operator or something similar?
> If not how would I find out if a certain list has a certain element?
> 
> Thank you,
> --
> Kyle
> 
> 


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




Re: newbie - in

2002-09-27 Thread david

Kyle Babich wrote:

> Does Perl have an in operator or something similar?
> If not how would I find out if a certain list has a certain element?
> 
> Thank you,
> --
> Kyle

simply loop through the list or array you have and see if you can find what 
you are looking for:

my @i = ( 1..100 );
my $found = 0;
#-- looking for 34
foreach my $j (@i){
#-- exit as soon as possible
$found = 1, last if($j == 34);
}

print $found ? "found 34\n" : "34 not found\n";

or use a hash for faster loop up:

my %h;
my @i = ( 1..100);
@h{@i} = ();
if(exists $h{34}){
print "found 34\n";
}else{
print "34 not found\n";
}

don't use hash if:

1. @i has duplicate value which you want to keep
2. order is important
3. @i is huge and takes up a lot of memory

david

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




RE: newbie - in

2002-09-27 Thread Nikola Janceski

And who would care if the list always remains small enough that it wouldn't
make a difference?
use grep, if you notice a performance issue at that command then it's time
to think of other methods of doing your operation (hint hashes).

Personally I avoid making giant arrays, heck I aviod too much data in memory
all together, but once you have to have too much data in memory you already
have a problem that you should be re-thinking to use less of it.

> -Original Message-
> From: Sudarshan Raghavan [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, September 29, 2002 4:01 AM
> To: Perl beginners
> Subject: RE: newbie - in
> 
> 
> On Fri, 27 Sep 2002, Timothy Johnson wrote:
> 
> > 
> > check out "perldoc -f grep"
> 
> grep should not be used for this purpose, it will run through 
> the entire 
> list even after the desired element has been found.
> 
> > 



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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