when using Data::Dumper
you will see that $l is seen as a string not an integer
print "LOG == ",$l,Dumper \$l,"\n";
LOG == 3$VAR1 = \'3';
As others pointed out log only returns floats up to certain precision, which IIRC also depends on the current implementation of Perl (that is compiling options).
And internally floats are stored in the string-slot of a variable.
That means the slight calculation error might be too small to be shown by a print but is still sufficient to let == fail.
Even if print would show the discrepancy, your approach wouldn't always work.
So better go the other way round and check if 125 == 5**$x with $x=int($l+$tolerance)
EDIT: The approach Moritz updated into his post is even better.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||