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 also critisized by some.

The tools you want for this are probably map and grep.

These commands are critisized by some, not entirely unfairly, because code written with them can be hard to understand for people not familiar with the constructs, and you can often get similar functionality out of more verbose (and, to some, ipso facto "clearer") code that doesn't use these constructs.

But to hell with all that -- if map & grep make sense to you, use them. If you are worried about maintainability -- and you should be -- then use comments to explain what you're doing.

Commands like these can make your code more compact (and, to some, ipso facto "clearer"), more efficient, and should be immediately clear to anyone that has put in the effort to become familiar with the language.




-- Chris Devers [EMAIL PROTECTED] http://devers.homeip.net:8080/blog/

np: 'Fuel'
     by Superman
     from 'Superman - 1940's Radio. eps 01-17'

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to