[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 exit early: > > my $found = 0; > for ( @array ) { > if ( $_ eq 'my string' ) { > $found = 1; > last; > } > } > > > If you need to determine the number of matches you can use grep: > > my $count = grep $_ eq 'my string', @array; > > > > John 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 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. So then I wonder - which is more efficient. My earlier "join" example, or a for loop? Thanks for all the input Darren -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>