-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemp.pl
62 lines (40 loc) · 1.04 KB
/
temp.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
=pod
=head1 NAME
temp.pl - Temperature conversion program
=head1 SYNOPSIS
temp.pl I<temp>(C|F)
=head1 DESCRIPTION
The I<temp.pl> converts Fahrenheit to Centigrade and vice versa.
For example 32 degrees Fahrenheit (32F) is 0 Centigrade (0C).
=head1 EXAMPLES
temp.pl 72F
72 F => 22.2222222222222 C
=head1 BUGS
The formatting of the output could be better.
=head1 AUTHOR
Steve Oualline, E<lt>oualline@www.oualline.comE<gt>.
=head1 COPYRIGHT
Copyright 2005 Steve Oualline.
This program is distributed under the GPL.
=cut
# convert Centigrade to Fahrenheit
# or vice versa.
use strict;
use warnings;
if (($#ARGV != 0) || ($ARGV[0] !~ /^([\-+]?\d+)([CcFf])$/)) {
print STDERR "Usage: $0 <deg>[C|F]\n";
exit (8);
}
my $temp = $1;
my $type = $2;
my $result;
my $result_type;
if (($type eq "C") || ($type eq "c")) {
$result = (9.0/5.0) * $temp + 32.0;
$result_type = "F";
} else {
$result = (5.0/9.0) * ($temp - 32.0);
$result_type = "C";
}
print "$temp $type => $result $result_type\n";