hash
para tener
parámetros con nombres.
1 #!/usr/bin/perl -w 2 print "Enter a temperature (i.e. 32F, 100C):\n"; 3 $input = <STDIN>; 4 chop($input); 5 6 if ($input !~ m/^([-+]?[0-9]+(\.[0-9]*)?)\s*([CF])$/i) { 7 print "Expecting a temperature, so don't understand \"$input\".\n"; 8 } 9 else { 10 $InputNum = $1; 11 $type = $3; 12 if ($type eq "C" or $type eq "c") { 13 $celsius = $InputNum; 14 $fahrenheit = ($celsius * 9/5)+32; 15 } 16 else { 17 $fahrenheit = $InputNum; 18 $celsius = ($fahrenheit -32)*5/9; 19 } 20 printf "%.2f C = %.2f F\n", $celsius, $fahrenheit; 21 } 22
Casiano Rodríguez León