User:Sburke/Gauges Generate


 * 1) !/usr/bin/perl
 * 2) Program to generate the table
 * 3)  http://en.wikipedia.org/wiki/Body_jewelry_sizes#Conversion_Table
 * 4) -- sburke@cpan.org  = http://en.wikipedia.org/wiki/User:Sburke
 * 5) Last Modified Time-stamp: "2012-06-05 22:32:56 MDT sburke@cpan.org"
 * 1) -- sburke@cpan.org  = http://en.wikipedia.org/wiki/User:Sburke
 * 2) Last Modified Time-stamp: "2012-06-05 22:32:56 MDT sburke@cpan.org"
 * 1) Last Modified Time-stamp: "2012-06-05 22:32:56 MDT sburke@cpan.org"
 * 1) Last Modified Time-stamp: "2012-06-05 22:32:56 MDT sburke@cpan.org"

use strict; use warnings; use constant DENOMINATOR => 16; use constant IN2MM => 25.4; use constant PLACEHOLDER => "&middot;"; use Math::BigInt ;

my @All;

sub to_thou { return sprintf '%01.3f', $_[0]; } my $QQ = '&'. "rdquo;"; #"\""; # my $MM = "mm"; #"mm"; # my $SP = "      ";
 * 1) print "Range: @range\n";

my @Gauge_Lines = grep m/\S/, split "\n", qq[ 20g 	0.812 	0.032 18g 	1.024 	0.040 16g 	1.291 	0.051 14g 	1.628 	0.064 12g 	2.053 	0.081 10g 	2.588 	0.102 8g 	3.264 	0.129 6g 	4.115 	0.162 4g 	5.189 	0.204 2g 	6.544 	0.258 0g 	8.251 	0.325 00g 	9.266 	0.365 (000g) 	10.404 	0.410 (0000g)	11.684 	0.460 ];
 * 1) The source numbers for this is from
 * 2)  http://en.wikipedia.org/wiki/American_Wire_Gauge

Main; exit;

sub Main { Setup_by_inch_fractions; Setup_by_gauges; Sort_All; Print_all_items; return }

sub Setup_by_inch_fractions {

for (   my $numerator = 1;       $numerator <= (DENOMINATOR*2);     ++$numerator ) {

my($i,$j) = ($numerator,DENOMINATOR);

#print "=== $i = $j\n";

my $int = "";

if($i >= $j) { # it's greater-or-eq 1"     $int = int($i/$j);      $i -= ($int * $j);    }

my $pretty_fraction;

if($i) { # there's a fractional part (...left) my $gcd = Math::BigInt::bgcd( $i,$j ); # ^= greatest common denominator $i /= $gcd; $j /= $gcd;

$pretty_fraction = $int ? "$$int $i/$j$"             : "$$i/$j$"      ;    } else { # it's simply an integer $pretty_fraction = $int; }   $pretty_fraction .= $QQ; my $improper_fraction = "$numerator/". DENOMINATOR; my $inch_decimal = to_thou(        $numerator/DENOMINATOR). $QQ; my $mm = to_thou(       (($numerator/DENOMINATOR) * IN2MM) ); add_to_all(     $mm, # the sort key,       #and now the rest:         "", #$gauge,         "\t\t\t\t\t$pretty_fraction",         $improper_fraction,         $inch_decimal,         $mm . $MM    ); } return; }

sub Print_all_items {

Print_header; foreach my $item (@All) { printf_all( @$item ); } print "|}\n\n\n"; return; }

sub add_to_all { my($sortkey, @rest) = @_; push @All, [$sortkey, [@rest]]; return; }

sub Sort_All {

@All = map {; $_->[1] } sort { $a->[0] <=> $b->[0] } @All ; }

sub Setup_by_gauges { foreach my $gauge_line (@Gauge_Lines) { my($g,$mm,$inch_decimal) = grep m/\S/, split m/\s+/, $gauge_line, ;   my $key = $mm; $mm             =~ s/^0//; #$inch_decimal =~ s/^0//; add_to_all(     $key,        "\t\t\t\t\t\t$g",         , #$pretty_fraction,        , #$improper_fraction,        $inch_decimal . $QQ,        $mm . $MM,    ) } return; }

sub Print_header {

print "\n\n", # Header: "{| class='wikitable'\n|-valign='center'|\n", join("\n", "$SP ! gauge (AWG)", "$SP ! inches fractional", "$SP | inches decimal", "$SP | millimeters",   ), "\n"; ; return; }

sub printf_all { my(@orig) = @_; $_[0] ||= PLACEHOLDER; $_[1] ||= PLACEHOLDER; $_[2] ||= (" ");

my $template = "\n|-align='right' $SP *1 %s $SP *2 %s $SP | %s $SP | %8s " ; if($orig[0]) { for($template){ s/\*1/!/; s/\*2/|/; }} if($orig[1]) { for($template){ s/\*1/|/; s/\*2/!/; }} my $n = sprintf $template, @_, ;

$n =~ s///; print $n; }

__END__