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
In reply to Celsius to Fahrenheit using s/// by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |