(SOLVED, <s>to the extent it actually needs to be, further minor issues are still here if you care</s>)
I'm at
Day 3 of one of those Learn The Bare Bones Of X Language In Y Days tutorials. If you'll hit End, you'll see the exercises I'm supposed to be doing. I'm having a bit of trouble with 1, though; this is my response to it (after much slimming-down):
#!/usr/bin/perl -w
use strict;
$count = .0;
until ($count == .9)
{
$count = $count + .1;
print ($count, "\n");
}
print ("End!\n");
Before I added -w and use strict;, the script would go into an infinite loop of this sort:
685.700000000087
685.800000000087
685.900000000087
686.000000000087
686.100000000087
I'm sure it's something to do with the fact that I'm using floating point values. When I replace them with whole numbers, it counts one to ten then prints End! just wonderfully.
I've tried zero-padding the values (as in 0.9 instead of .9) as well; this makes no difference.
When I added -w and use strict;, I get this:
-bash-2.05b$ perl count
Global symbol "$count" requires explicit package name at count line 4.
{same for $count at lines 6, 8, 8, and 10}
Execution of count aborted due to compilation errors.
Am I supposed to be declaring $count as a floating point variable somehow?
I searched and found a post or two that said something about trying to compare floating point values being a Bad Idea. Am I doing something wrong, or will this just never work?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.