Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Need to match number other than 1

by lodin (Hermit)
on Nov 29, 2007 at 17:28 UTC ( [id://653926]=note: print w/replies, xml ) Need Help??


in reply to Re: Need to match number other than 1
in thread Need to match number other than 1

You don't have to generate any code. The (?(COND)TRUE|FALSE) assertion fits the glove here. $^N can be used instead of $1 here, making it copy-paste safe.

I'd also like to draw some attention to Regexp::Common::number. These changes would make

my $num1 = qr{^ (?> ([\.\d]+) ) (??{$1 == '1' ? '(?!)' : '' }) }x;
become
use Regexp::Common qw/ number /; my $num1 = qr{^ (?> ($RE{num}{dec}) ) (?(?{ $^N != '1' })|(?!)) }x;
I reversed the logic in the COND block so that it reads better to me. "Match a number, the number isn't 1, done".

lodin

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-29 09:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found