Re: Coordinate validator

by jwkrahn (Monsignor)
 on May 18, 2019 at 04:35 UTC Need Help??

I ran your program which output:

```
Not ok cases

N65, N25
N65, N25
too many lats or lons
Err: 1

65P, E25
65P, E25
too many lats or lons
Err: 1

91, 47
91, 47
numbers are too big
LAT: 91 LON: 47

65P, W25
65P, W25
mixed languages
Err: 1

100 E, 91 N
N91 ,E100
numbers are too big
LAT: 91 LON: 100

47.9805, -186.5586
47.9805, -186.5586
numbers are too big
LAT: 47.9805 LON: -186.5586

You have 13 error tests in your program:

```1:   74         if((\$ENG >0) && (\$FIN > 0)) {
75                 print "mixed languages\n";
76                 \$err++
77         }
2:   78         elsif ((\$FIN>0) && ( (\$H{I}+\$H{L})>1 || (\$H{E}+\$H{P})>
+1 )) {
79                 print "too many lats or lons\n";
80                 \$err++
81         }
3:   82         elsif ((\$ENG>0) && ( (\$H{N}+\$H{S})>1 || (\$H{W}+\$H{E})>
+1 )) {
83                 print "too many lats or lons\n";
84                 \$err++
85         }
4:   86         elsif (\$H{E}>1) {
87                 print "too many E\n";
88                 \$err++
89         }
5:   90         elsif (\$H{I}>1) {
91                 print "too many I\n";
92                 \$err++
93         }
6:   94         elsif (\$H{L}>1) {
95                 print "too many L\n";
96                 \$err++
97         }
7:   98         elsif (\$H{P}>1) {
99                 print "too many P\n";
100                 \$err++
101         }
8:  102         elsif (\$H{W}>1) {
103                 print "too many W\n";
104                 \$err++
105         }
9:  106         elsif (\$H{S}>1) {
107                 print "too many S\n";
108                 \$err++
109         }
10: 110         elsif (\$H{N}>1) {
111                 print "too many N\n";
112                 \$err++
113         }
...
11: 133         elsif (\$comma_count > 3) {
134                 print "too many commas\n";
135                 \$err++
136         }
12: 137         elsif (\$dot_count > 2) {
138                 print "too many dots\n";
139                 \$err++;
140         }
...
13: 169                 if (\$coords =~ /^[-+]?([1-8]?\d(\.\d+)?|90(\.0
++)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?    169 )\$/)
+{
170                         print "all ok\n";
171                 } else {
172                         print "too big numbers\n";
173                 }

But only 1, 2, 3 and 13 are actually tested for in your test data.

Also, tests 4 through 10 can be combined into one test:

```        elsif ( my @keys = grep \$H{ \$_ } > 1, keys %H ) {
for ( @keys ) {
print "too many \$_\n";
\$err++
}
}

Although this test will never execute because tests 2 and 3 take presedense.

Also this:

```     30         my %H;
...
61         \$H{E} = (\$_ =~ tr/E//);
62
63         \$H{I} = (\$_ =~ tr/I//);
64         \$H{P} = (\$_ =~ tr/P//);
65         \$H{L} = (\$_ =~ tr/L//);
66
67         \$H{W} = (\$_ =~ tr/W//);
68         \$H{N} = (\$_ =~ tr/N//);
69         \$H{S} = (\$_ =~ tr/S//);

Could be simplified a bit:

```        my %H = (
E => tr/E//,

I => tr/I//,
P => tr/P//,
L => tr/L//,

W => tr/W//,
N => tr/N//,
S => tr/S//,
);

And finally, you use tr/// for counting but you could also use it in a few other places:

```      7         \$in =~ s/[NWSEIPL]//g;

\$in =~ tr/NWSEIPL//d;

39         s/[^0-9NWSEIPL,.+-]/ /g;

tr/0-9NWSEIPL,.+-/ /c;

122                 s/ /./g;

tr/ /./;

126                 s/,/./g;

tr/,/./;

148                 s/[NE]//g;

tr/NE//d;

156                 s/[IP]//g;

tr/IP//d;

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2019-10-14 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2019 the site I miss most is:

Results (36 votes). Check out past polls.

Notices?