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 |