Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152016]
help
Chatterbox?
[shmem]: J.S.Bach said: "playing Clavier is darn easy. All you have to do is to push the right key with the right finger at the right time."
[shmem]: same for programming and creating bugs.
[choroba]: programming is easy once you know how to solve the problem
[shmem]: choroba: yeah, adjusting the screw 2 - knowing which one 42

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-04-27 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (508 votes). Check out past polls.