Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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!


In reply to for loop localisation bug? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-24 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found