--- Aaron Craig <[EMAIL PROTECTED]> wrote:

> Your example is wonderfully concise -- is there any way that you can
> expand on this to get more information out of the test, ie which
> member of the array matches, or returning the member if this were
> in a function?

Yes.

...oh, you mean you want me to do so? lol!

Ok, let's get a little more info out of it. =o)
 
 $TEST1 = "030";
 @HOLDER = ("020", "040", "034", "056", "030");

 @hits = grep /^$TEST1$/, @HOLDER;
 $hits = scalar @hits;

You see, grep() returns an array of those elements from it's input list
that match its test condition. This would only give you those elements
of @HOLDER that exactly match $TEST1, and would store them in @hits so
that you would be able to tell how many there were. An array in a
scalar context yields its number of elements, so $hits is how many
there were (which can be none). the "scalar" keyword in this example is
optional, but it's clearer if you add it.

No complicated algorithm required, though there is *ALWAYS* more than
one way to do it, and sometimes others are more efficient.... but
efficiency is not always more important than readability. ;o]

=====
print "Just another Perl Hacker\n"; # edited for readability =o)
=============================================================
Real friends are those whom, when you inconvenience them, are bothered less by it than 
you are. -- me. =o) 
=============================================================
"There are trivial truths and there are great Truths.
 The opposite of a trival truth is obviously false.
 The opposite of a great Truth is also true."  -- Neils Bohr

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to