UPDATE: Fixed regex to find decimals, after JDPorter pointed out the problem below. (And before Tanktalus beat me to it ;) )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. +) while (<DATA>) { chomp; my $celsius = my $fahrenheit = $_; #was $fahrenheit =~ s|(\d+)C|($1*9/5)+32 . "F"|ge; $fahrenheit =~ s|(\d+\.\d+)C|($1*9/5)+32 . "F"|ge; print "$celsius is $fahrenheit\n"; } #Outputs: #12C is 12C #16.5C is 61.7F #-40C is -40C __DATA__ 12C 16.5C -40C
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Celsius to Fahrenheit using Regexp::Common
by tphyahoo (Vicar) on Feb 09, 2005 at 11:02 UTC | |
|
Re: Celsius to Fahrenheit using s///
by jdporter (Paladin) on Feb 08, 2005 at 15:11 UTC | |
by Tanktalus (Canon) on Feb 08, 2005 at 15:31 UTC | |
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 |