while (<DATA>) { chomp; my $was = $_; my %formulae = (C => sub { ((shift() * 9/5) + 32).'F' }, F => sub { ((shift() - 32) * 5/9).'C' }); s{(.*)([CF])}{${\$formulae{$2}($1)}}; # Update: look, ma! No "e" print "$was is $_\n"; } __DATA__ 12C 13C 14C 15C -40C +32C .5C 15.8C 60.44F 55.4F -.7F
In reply to Re^4: Celsius to Fahrenheit using s///
by Roy Johnson
in thread Celsius to Fahrenheit using s///
by tphyahoo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |