Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Match multiple number

by tobyink (Canon)
on Aug 17, 2018 at 18:45 UTC ( [id://1220531]=note: print w/replies, xml ) Need Help??


in reply to Match multiple number

Use modulo arithmetic.

if ($Number % 5 == 0){ ...; }

Alternatively, as all multiples of five end in a 5 or a 0, you can do something like this:

if ($Number =~ /^-?[0-9]*[05]$/){ ...; }

In both these cases, I'm allowing negative values, like -5 and -10. If you prefer to only allow non-negative values:

if ($Number % 5 == 0 and $Number >= 0){ ...; }
if ($Number =~ /^[0-9]*[05]$/){ ...; }

Replies are listed 'Best First'.
Re^2: Match multiple number
by IB2017 (Pilgrim) on Aug 18, 2018 at 10:44 UTC

    Thank you very much. I like these solutions.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found