Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: searching an array?

by Parham (Friar)
on Mar 15, 2002 at 16:22 UTC ( #152016=note: print w/replies, xml ) Need Help??

in reply to searching an array?

if ( grep(/^$path$/, @directories) ) { #exact input to array element s +earch print "$path exists in the array of directories"; }
that's how i'd do it. If grep() gets anything (in the conditional if statement), the program will tell you that your input exists in the array. If you want partial searches in the array, remove the ^ or $ or both depending on whether you want your input to exist in the beginning or the ending or anywhere of each array element.

Replies are listed 'Best First'.
Re: Re: searching an array?
by Whitchman (Novice) on Mar 15, 2002 at 22:27 UTC
    Thanks everyone! That did the trick. You guys are fast!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152016]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2016-10-23 02:22 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (300 votes). Check out past polls.