If you want to avoid "-0", my order of prefence would be: 1) store it as decimal; 2) store it as [$sign, $deg, $min, $sec] where all four are integers, with sign taking on -1 for negative angles; 3) store it as [$deg, $min, $sec, $sign] (but I don't like that order as much).
For accepting integer input, I'd just only allow sign on the degrees... so if you wanted to allow "-0 1 0", that would be interpreted as -1min. Since "input" implies "text" in my mind, you can just check for (and strip) the sign using text processing, and then re-apply the sign once you are done:
... or maybe ...$input = "-0 1 0"; my $sign = ($input =~ /^\s*-/) ? -1 : 1; my ($d,$m,$s) = map abs, split / /, $input; my $decdegrees = $sign * ($d + $m/60 + $s/3600); print $decdegrees
.$input = "-0 1 0"; my ($sign, $d, $m, $s) = ($input =~ /(-{0,1})(\d+)\s+(\d+)\s+(\d+)/); my $decdegrees = (($sign)?-1:1) * ($d + $m/60 + $s/3600); print $decdegrees
update: fix missing code tags
In reply to Re^9: How to write testable command line script?
by pryrt
in thread How to write testable command line script?
by thechartist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |