When I run the following Perl one-liner:
$ perl -e 'print "Oh no!\n" unless 1835 == 100*18.35'
I get
Oh no!
Why is that?
When I run the following Perl one-liner:
$ perl -e 'print "Oh no!\n" unless 1835 == 100*18.35'
I get
Oh no!
Why is that?
Copyright © 2021 Jogjafile Inc.
What you're missing is an old computer science problem - floating point conversion.
You see, you cannot precisely represent '0.35' as a floating point number since it's a periodic number in binary.
So if you add:
You'll get:
$a->{a}is very slightly more than$band thus the test is correct.You can see this at work if you:
Whilst we're at it though - don't use
$aor$b- they're reserved forsort. And single letter var names aren't good style anyway.Also
my $a = {};is redundant - there's no need to initialise an empty hash-reference like that.To do what you want, then you either need to compare 'like types' or cast explicitly to integer: