BlinkenArea - GitList
Repositories
Blog
Wiki
partlib
Code
Commits
Branches
Tags
Search
Tree:
cd92b87
Branches
Tags
master
stefan.experimental
partlib
pcb_stuff
units.pl
move scripts into own subdir
Stefan Schuermans
commited
cd92b87
at 2014-01-11 13:44:27
units.pl
Blame
History
Raw
#! /usr/bin/perl use strict; use warnings; print <<EOF; units calculator by stefan\@blinkenarea.org enter expressions to calculate supported suffixes on numbers: mm millimeters mil 1/1000 inch pcb PCB file units (default) examples: 3.5mm+1.2mil enter EOF (control D) to end program EOF while( 1 ) { print "> "; my $line = <>; if( ! $line ) { last; } chomp $line; chomp $line; if( $line ne "" ) { $line =~ s/([0-9]*(\.[0-9]*)?)mm/($1\/0.000254)/g; $line =~ s/([0-9]*(\.[0-9]*)?)mil/($1\/0.01)/g; $line =~ s/([0-9]*(\.[0-9]*)?)pcb/($1\/1.0)/g; $line =~ s/[^0-9.()*\/+-]//g; # this is important for letting through only arithmetic expressions my $result = eval( $line ); if( defined $result ) { printf( "%f\n%fmm\n%fmil\n%fpcb\n", $result, $result * 0.000254, $result * 0.01, $result * 1.0 ); } else { print( "error\n" ); } } # if( $line ne "" ) } # while( 1 )