in reply to Re: Celsius to Fahrenheit using s///
in thread Celsius to Fahrenheit using s///
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Celsius to Fahrenheit using s///
by saskaqueer (Friar) on Feb 08, 2005 at 18:15 UTC | |
by Roy Johnson (Monsignor) on Feb 08, 2005 at 19:57 UTC | |
by trammell (Priest) on Feb 08, 2005 at 21:32 UTC | |
by Anonymous Monk on Feb 09, 2005 at 05:08 UTC |