#!/usr/bin/env perl # Noise Figure and Temperature Conversion sub Print { $db = 10 * (log(1 + ($k / 290)) * 0.43429); printf "\n\n dB : %.5f\n", $db; printf " Kelvin : %.5f\n", $k; printf " degrees Celsius : %.5f\n", $k - 273.16; printf " degrees Fahrenheit : %.5f\n\n", (1.8 * $c) + 32; } while (!$ans || $ans > 4 || $ans =~ m/[a-z]/i) { print "\33[H\33[J". "\tNoise Figure and Temperature Conversion\n\n". "1) dB to Kelvin, Celsius, and Fahrenheit\n". "2) Kelvin to dB, Celsius, and Fahrenheit\n". "3) Celsius to dB, Kelvin, and Fahrenheit\n". "4) Fahrenheit to dB, Kelvin, and Celsius\n\n". "Enter your selection: "; chomp($ans = ); } if ($ans == 1) { print "\n"; while (!$db) { print "Enter noise figure (in dB): "; chomp($db = ); $db =~ tr/0-9.//csd; } $k = 290 * (10 ** ($db / 10) - 1); &Print; } elsif ($ans == 2) { print "\n"; while (!$k) { print "Enter noise temperature in K: "; chomp($k = ); $k =~ tr/0-9.//csd; } &Print; } elsif ($ans == 3) { print "\n"; while (!$c) { print "Enter degrees Celsius: "; chomp($c = ); $c =~ tr/0-9.//csd; } &Print($k = $c + 273.16); } elsif ($ans == 4) { print "\n"; while (!$f) { print "Enter degrees Fahrenheit: "; chomp($f = ); $f =~ tr/0-9.//csd; } $c = (5 / 9) * ($f - 32); &Print($k = $c + 273.16); }