If you want to act upon one or more occurences of $path in @directories, then you're right on target. In your case, you might want to exit the loop when you have a hit, but that depends upon if you expect to have the same path in your @directories more than once.
grep() is good for this stuff as well, but only if you want to create a new array with all scalars from @directories that match your $path. (I.e. a subset of @directories)
map() is fine if you want to create a new array with all scalars from @directories but you want to conditionally make changes to some or all scalars before they go into your new array.
Do not use grep() or map() unless you intend to use the array returned. (This is in the FAQ. Read it.)
In reply to Re: searching an array?
by Biker
in thread searching an array?
by Whitchman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |