flat_black
Member
I don't know why I wrote this, but I did it a long time ago, and I remember having an intention that it was going to be used on some web page I was writing, but that just goes to show you that I've totally become distracted from that. =) Anyway, I might put it up somewhere at some point, but here's the source. By the by, I wrote this a couple of years ago. Hehe:
Code:
#!/usr/bin/perl
#
# Engine Displacement Calculator - Eddie Howe ( casida@bluebottle.com )
#
# I wrote this with the intention to implement it into command line or web
# page use, as so desired. The -c function just concatinates data from the
# command line in the form of bore, stroke, then cylinder number. The -r
# functions as a means to do the same as -c, only designed to output the raw
# data only, for web site usage. Do with this what you will, just please
# leave the line with my name and e-mail in. Thanks!
my $qpi = .7854;
&sortvars;
&output;
sub sortvars {
if($ARGV[0] eq "-c" || $ARGV[0] eq "-r") {
our $bore = $ARGV[1];
our $stroke = $ARGV[2];
our $cyl = $ARGV[3];
} else {
print "Bore (mm): ";
our $bore = <STDIN>;
print "Stroke (mm): ";
our $stroke = <STDIN>;
print "Cylinders: ";
our $cyl = <STDIN>;
print "---------------------------\n";
}
}
sub output {
my $ccdisp = $bore*$bore*$stroke*$qpi*$cyl/1000;
if($ARGV[0] eq "-r") {
printf "%.2f", $ccdisp;
} else {
printf "Displacement (cc): %.2f\n", $ccdisp;
}
}