No such thing as a small change PerlMonks

### Re^8: How to write testable command line script?

by thechartist (Monk)
 on Nov 26, 2018 at 17:51 UTC ( #1226376=note: print w/replies, xml ) Need Help??

Ah. I think I understand now. Thanks for catching my error. I have no idea why I didn't consider that initially. Back to the drawing board.

Edit: What do you think the best way of representing the degree:min:sec is? I am leaning to simply converting everything to seconds, doing the arithmetic, and then converting to deg:min:sec format as Anomalous Monk did. I planned on extending the calculator to accept decimals anyway. But if I wanted to accept integer input, what would be the best way of representing this situation of small negatives?

Storing the -0 as text does not appeal to me.

• Comment on Re^8: How to write testable command line script?

Replies are listed 'Best First'.
Re^9: How to write testable command line script?
by pryrt (Monsignor) on Nov 26, 2018 at 18:41 UTC

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:

```\$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
... or maybe ...
```\$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

Create A New User
Node Status?
node history
Node Type: note [id://1226376]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2020-10-24 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favourite web site is:

Results (242 votes). Check out past polls.

Notices?