in reply to How do I detect if a number has a minus sign?
To test for a negative:if ($fraction =~ /^((-) ?)?((\d+) )?(\d+) ?\/ ?(\d+)$/) { $fraction = ($2 ? -1 : 1) * ($4 + $5 / $6); }
if ($fraction =~ /^((-) ?)?((\d+) )?(\d+) ?\/ ?(\d+)$/ && $2) { #run if negative... }
|
|---|