Re: searching a whole array without using a loop

2004-08-24 Thread John W. Krahn
Darren Birkett wrote: OK, to be more specific, I'm using Net::Telnet:Cisco. When logged onto a device I'm using the "show version" command, and storing the output in an array. Each element of the array will therefore contain lots of rubbish. I just want to match certain keyword(s) to determin

Re: searching a whole array without using a loop

2004-08-24 Thread Gunnar Hjalmarsson
James Edward Gray II wrote: Gunnar Hjalmarsson wrote: if ( grep /my string/, @myarray ) { some code } Ordinarily, I wouldn't even mention this, but since the conversation is about what is fastest... The OP was not about what is fastest at all. It was about whether there is "a better

Re: searching a whole array without using a loop

2004-08-24 Thread James Edward Gray II
On Aug 24, 2004, at 9:14 AM, Gunnar Hjalmarsson wrote: Isn't grep() "specific" enough? Initially you said: $line = join(' ',@myarray); if ($line =~ /my string/) { some code } The equivalent using grep() would be: if ( grep /my string/, @myarray ) { some code } Or

Re: searching a whole array without using a loop

2004-08-24 Thread James Edward Gray II
On Aug 24, 2004, at 7:48 AM, Darren Birkett wrote: OK, to be more specific, I'm using Net::Telnet:Cisco. When logged onto a device I'm using the "show version" command, and storing the output in an array. Each element of the array will therefore contain lots of rubbish. I just want to match cer

Re: searching a whole array without using a loop

2004-08-24 Thread Gunnar Hjalmarsson
Darren Birkett wrote: I just want to match certain keyword(s) to determine device type. I guess a for loop is the closest I'm going to get. I just thought there would be a specific function for this. Isn't grep() "specific" enough? Initially you said: $line = join(' ',@myarray); if ($line

Re: searching a whole array without using a loop

2004-08-24 Thread Darren Birkett
[EMAIL PROTECTED] (John W. Krahn) wrote in news:[EMAIL PROTECTED]: > > If all the elements are unique then use a hash. > > if ( exists $hash{ 'my string' } ) { > # do something > } > > > The most efficient way to determine if an element exists in an array > is to use a for loop and

Re: searching a whole array without using a loop

2004-08-23 Thread John W. Krahn
Darren Birkett wrote: Hi, Hello, Is there a better way to search all elements of an array for a string (without using a loop to test individual elements) than: $line = join(' ',@myarray); if ($line =~ /my string/) { some code } I've seen map and grep used by some but also critisized by so

Re: searching a whole array without using a loop

2004-08-23 Thread Chris Devers
On Mon, 23 Aug 2004, Darren Birkett wrote: Is there a better way to search all elements of an array for a string (without using a loop to test individual elements) than: $line = join(' ',@myarray); if ($line =~ /my string/) { some code } I've seen map and grep used by some but

searching a whole array without using a loop

2004-08-23 Thread Darren Birkett
Hi, Is there a better way to search all elements of an array for a string (without using a loop to test individual elements) than: $line = join(' ',@myarray); if ($line =~ /my string/) { some code } I've seen map and grep used by some but also critisized by some. I thought there might