in reply to Re^3: Celsius to Fahrenheit using s///
in thread Celsius to Fahrenheit using s///

Is this better, or worse?
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

Caution: Contents may have been coded under pressure.