in reply to Pattern Matching Query

Update: Added missing brackets and an afterthought at the bottom. And corrected the error blakem pointed out below.

You don't need a regex, a simple index will do fine. This has the additional benefit that $run will give you a comparative value for determining the value of the hand.

if (($run = index('abcdefghijklm', $sorted_values,0)) > -1) { # Do stuff... }

In fact, if you arranged for your sort of the cards to sort aces above kings, then you could use the $run values to determine which run has the higher scoring value. (I think. I'm not much of a card player :^)


Well It's better than the Abottoire, but Yorkshire!

Replies are listed 'Best First'.
Re: Re: Pattern Matching Query
by blakem (Monsignor) on Sep 17, 2002 at 12:55 UTC
    A return value of 0 from index actually means it found the substr at position 0. An rv of -1 indicates failure. Therefore:
    if (index('abcdefghijklm', $sorted_values) > -1) { # Do stuff... }

    -Blake