http://qs321.pair.com?node_id=11113631


in reply to number comparison with a twist

Below does not apply to other example data posted later.


What about doing the comparison after converting the string to integer AFTER removing the decimal point ($x =~ s,\.,, ; $x = int( $x ) ; $x == $y ? ... : ... ;)? Won't that work?

# Uses addition to 0 instead of int() to force conversion to number fr +om string. use strict; use warnings; my @compare = ( [ 1990, '19.90' ], [ 465, '4.65' ] ); for my $pair ( @compare ) { my $from_api = $pair->[1]; $from_api =~ s,\.,, ; $from_api += 0; printf "%0.f =?= %0.f => %s\n", $from_api, $pair->[0], ( $from_api == $pair->[0] ? 'same' : 'different' ) ; }