Created
October 16, 2022 04:55
-
-
Save jaggzh/011198b4c6e35c757a28dc1f56537721 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use 5.24.0; | |
| use Text::Table; | |
| my $data = <<'EOT'; | |
| 1/16 1.5875 | |
| 1/8 3.1750 | |
| 3/16 4.7625 | |
| 1/4 6.3500 | |
| 5/16 7.9375 | |
| 3/8 9.5250 | |
| 7/16 11.1125 | |
| 1/2 12.7000 | |
| 9/16 14.2875 | |
| 5/8 15.8750 | |
| 11/16 17.4625 | |
| 3/4 19.0500 | |
| 13/16 20.6375 | |
| 7/8 22.2250 | |
| 15/16 23.8125 | |
| 1 25.4001 | |
| 1-1/16 26.9876 | |
| 1-1/8 28.5751 | |
| 1-3/16 30.1626 | |
| 1-1/4 31.7501 | |
| 1-5/16 33.3376 | |
| 1-3/8 34.9251 | |
| 1-7/16 36.5126 | |
| 1-1/2 38.1001 | |
| 1-9/16 39.6876 | |
| 1-5/8 41.2751 | |
| 1-11/16 42.8626 | |
| 1-3/4 44.4501 | |
| 1-13/16 46.0376 | |
| 1-7/8 47.6251 | |
| 1-15/16 49.2126 | |
| 2 50.8001 | |
| 2-1/16 52.3876 | |
| 2-1/8 53.9751 | |
| 2-3/16 55.5626 | |
| 2-1/4 57.1501 | |
| 2-5/16 58.7376 | |
| 2-3/8 60.3251 | |
| 2-7/16 61.9126 | |
| 2-1/2 63.5001 | |
| 2-9/16 65.0876 | |
| 2-5/8 66.6751 | |
| 2-11/16 68.2626 | |
| 2-3/4 69.8501 | |
| 2-13/16 71.4376 | |
| 2-7/8 73.0251 | |
| 2-15/16 74.6126 | |
| 3 76.2002 | |
| 3-1/16 77.7877 | |
| 3-1/8 79.3752 | |
| 3-3/16 80.9627 | |
| 3-1/4 82.5502 | |
| 3-5/16 84.1377 | |
| 3-3/8 85.7252 | |
| 3-7/16 87.3127 | |
| 3-1/2 88.9002 | |
| 3-9/16 90.4877 | |
| 3-5/8 92.0752 | |
| 3-11/16 93.6627 | |
| 3-3/4 95.2502 | |
| 3-13/16 96.8377 | |
| 3-7/8 98.4252 | |
| 3-15/16 100.013 | |
| 4 101.600 | |
| 4-1/16 103.188 | |
| 4-1/8 104.775 | |
| 4-3/16 106.363 | |
| 4-1/4 107.950 | |
| 4-5/16 109.538 | |
| 4-3/8 111.125 | |
| 4-7/16 112.713 | |
| 4-1/2 114.300 | |
| 4-9/16 115.888 | |
| 4-5/8 117.475 | |
| 4-11/16 119.063 | |
| 4-3/4 120.650 | |
| 4-13/16 122.238 | |
| 4-7/8 123.825 | |
| 4-15/16 125.413 | |
| 5 127.00 | |
| 5-1/16 128.588 | |
| 5-1/8 130.175 | |
| 5-3/16 131.763 | |
| 5-1/4 133.350 | |
| 5-5/16 134.938 | |
| 5-3/8 136.525 | |
| 5-7/16 138.113 | |
| 5-1/2 139.700 | |
| 5-9/16 141.288 | |
| 5-5/8 142.875 | |
| 5-11/16 144.463 | |
| 5-3/4 146.051 | |
| 5-13/16 147.638 | |
| 5-7/8 149.225 | |
| 5-15/16 150.813 | |
| 6 152.400 | |
| 6-1/16 153.988 | |
| 6-1/8 155.575 | |
| 6-3/16 157.163 | |
| 6-1/4 158.750 | |
| 6-5/16 160.388 | |
| 6-3/8 161.925 | |
| 6-7/16 163.513 | |
| 6-1/2 165.100 | |
| 6-9/16 166.688 | |
| 6-5/8 168.275 | |
| 6-11/16 169.863 | |
| 6-3/4 171.450 | |
| 6-13/16 173.038 | |
| 6-7/8 174.625 | |
| 6-15/16 176.213 | |
| 7 177.800 | |
| 7-1/16 179.388 | |
| 7-1/8 180.975 | |
| 7-3/16 182.563 | |
| 7-1/4 184.150 | |
| 7-5/16 184.738 | |
| 7-3/8 187.325 | |
| 7-7/16 188.913 | |
| 7-1/2 190.500 | |
| 7-9/16 192.088 | |
| 7-5/8 193.675 | |
| 7-11/16 195.263 | |
| 7-3/4 196.850 | |
| 7-13/16 198.438 | |
| 7-7/8 200.025 | |
| 7-15/16 201.613 | |
| 8 203.200 | |
| 8-1/16 204.788 | |
| 8-1/8 206.375 | |
| 8-3/16 207.963 | |
| 8-1/4 209.550 | |
| 8-5/16 211.138 | |
| 8-3/8 212.725 | |
| 8-7/16 214.313 | |
| 8-1/2 215.900 | |
| 8-9/16 217.488 | |
| 8-5/8 219.075 | |
| 8-11/16 220.663 | |
| 8-3/4 222.250 | |
| 8-13/16 223.838 | |
| 8-7/8 225.425 | |
| 8-15/16 227.013 | |
| 9 228.600 | |
| 9-1/16 230.188 | |
| 9-1/8 231.775 | |
| 9-3/16 233.363 | |
| 9-1/4 234.950 | |
| 9-5/16 236.538 | |
| 9-3/8 238.125 | |
| 9-7/16 239.713 | |
| 9-1/2 241.300 | |
| 9-9/16 242.888 | |
| 9-5/8 244.475 | |
| 9-11/16 246.063 | |
| 9-3/4 247.650 | |
| 9-13/16 249.238 | |
| 9-7/8 250.825 | |
| 9-15/16 252.413 | |
| 10 254.001 | |
| 10-1/16 255.588 | |
| 10-1/8 257.176 | |
| 10-3/16 258.763 | |
| 10-1/4 260.351 | |
| 10-5/16 261.938 | |
| 10-3/8 263.526 | |
| 10-7/16 265.113 | |
| 10-1/2 266.701 | |
| 10-9/16 268.288 | |
| 10-5/8 269.876 | |
| 10-11/16 271.463 | |
| 10-3/4 273.051 | |
| 10-13/16 274.638 | |
| 10-7/8 276.226 | |
| 10-15/16 277.813 | |
| 11 279.401 | |
| 11-1/16 280.988 | |
| 11-1/8 282.576 | |
| 11-3/16 284.163 | |
| 11-1/4 285.751 | |
| 11-5/16 287.338 | |
| 11-3/8 288.926 | |
| 11-7/16 290.513 | |
| 11-1/2 292.101 | |
| 11-9/16 293.688 | |
| 11-5/8 295.276 | |
| 11-11/16 296.863 | |
| 11-3/4 298.451 | |
| 11-13/16 300.038 | |
| 11-7/8 301.626 | |
| 11-15/16 303.213 | |
| 12 304.801 | |
| EOT | |
| sub imp2d { | |
| my $s = shift; | |
| # say ""; | |
| # say " S: {$s}"; | |
| return int($s) if $s !~ /-/; | |
| my ($whole, $f1, $f2) = ($s =~ m|^(.*)-(\d+)/(\d+)|); | |
| my $frac = (int($f1)/int($f2)); | |
| my $res = int($whole)+$frac; | |
| # say "Whole: $whole"; | |
| # say " f1: $f1"; | |
| # say " f2: $f2"; | |
| # say " Frac: $frac"; | |
| # say " Res: $res"; | |
| return $res; | |
| } | |
| my @lines = split(/\n/, $data); | |
| my @met = map { my $s=$_; $s =~ s/^.*?\s//; $s; } @lines; | |
| my @imp = map { my $s=$_; $s =~ s/\s.*$//; { imp => $s, dec => imp2d($s) }; } @lines; | |
| #my @imp = map { my $s=$_; $s =~ s/\s.*$//; $s; } @lines; | |
| say "Last line: ", $lines[-2]; | |
| say " Imp -1: ", $imp[-2]->{imp}; | |
| say "ImpDec -1: ", $imp[-2]->{dec}; | |
| my $tb = Text::Table->new(qw/Metric Imperial Imperial(Dec)/); | |
| for my $i (0 .. $#lines) { | |
| $tb->add($met[$i], $imp[$i]->{imp}, $imp[$i]->{dec}); | |
| } | |
| open my $pipe, "|-", "less"; $|=1; print $pipe $tb; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment