in reply to Squeezing $a+1 to be magical like $a++
Of course you can overload the '+' with this sub.sub format_add{ my ($x, $y) = @_; my $ret = $x + $y; my $digs = length $x; sprintf("%0${digs}d", $ret ); }
$a=0.5; print ++$a; #prints 1.5 $a='a0.5'; print ++$a; #prints a6 #(so ++ ignores the dot and squashes the 0) $a='2a'; print ++$a; #prints 3 #(because 2a in numeric context returns 2)
Apparently it is a beast to handle with care.
Jeroen
"We are not alone"(FZ)
|
|---|