Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^9: How to write testable command line script?

by pryrt (Abbot)
on Nov 26, 2018 at 18:41 UTC ( [id://1226379]=note: print w/replies, xml ) Need Help??


in reply to Re^8: How to write testable command line script?
in thread How to write testable command line script?

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-04-23 13:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found