Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Pattern Matching Query

by BrowserUk (Patriarch)
on Sep 17, 2002 at 12:46 UTC ( [id://198473]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://198473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 02:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found