Am I being dumb, or should the value of $n be 50 after the for loop in the following code?
#! perl -slw
use strict;
$| = 1;
print 'Perl version is: ', $];
my $n;
for $n ( 1 .. 100 ) {
printf "\r%d", $n;
last if $n == 50;
}
print "\nThe value of the counter after the loop is $n";
__END__
P:\test>perl5.6.1 junk.pl8
Perl version is: 5.006001
50Use of uninitialized value in concatenation (.) or string at junk.pl
+8 line 14.
The value of the counter after the loop is
P:\test>junk.pl8
Perl version is: 5.008
50Use of uninitialized value in concatenation (.) or string at P:\test
+\junk.pl8 line 14.
The value of the counter after the loop is
I'd would assume that this is a bug accept it seems strange that it apparently affects versions back as far as 5.6.1 and hasn't been noticed before.
If this isn't just me having brain fade, could someone test if it still exists on 5.8.2 and/or other platforms?
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Hooray!
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.