Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: When greedy constructs do battle, can I choose the winner?

by ikegami (Patriarch)
on Sep 20, 2007 at 18:55 UTC ( [id://640213]=note: print w/replies, xml ) Need Help??


in reply to When greedy constructs do battle, can I choose the winner?

Yes, by placing it first.

my ($last_five) = map scalar reverse, map /^(?>0*)(\d{1,5})/, map scalar reverse, $running_total;

But note that I had to add (?>...) in order to prevent backtracking in the situation where the input is "0000". It's simpler to make sure the last of 5 isn't a 0.

my ($last_five) = $running_total =~ /(\d{0,4}[^0\D])0*$/;

or

my ($last_five) = $running_total =~ /(\d{1,5}(?<!0))0*$/;

In all of the above solutions, $last_five will be undef if there's no match.

Tested.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found