Almost as easy to fix it as to find the problem ;->
use strict; use warnings; # From http://prometheus.frii.com/%7Egnat/yapc/2000-stages/slide31.htm +l # Fixed a typo in the regex (Nathan forgot to escape the forwardslash. +) # Fixed number problems - allow +/-, and decimals. Exponentials still + not allowed. while (<DATA>) { chomp; my $celsius = my $fahrenheit = $_; $fahrenheit =~ s|([+-]?(?:\d*\.)?\d+)C|($1*9/5)+32 . "F"|ge; print "$celsius is $fahrenheit\n"; } #Outputs: #12C is 53.6F #13C is 55.4F #14C is 57.2F #15C is 59F #-40C is -40F #+32C is 89.6F #.5C is 32.9F #15.8C is 60.44F __DATA__ 12C 13C 14C 15C -40C +32C .5C 15.8C
In reply to Re^2: Celsius to Fahrenheit using s///
by Tanktalus
in thread Celsius to Fahrenheit using s///
by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |