Hello GrandFather,

In my reply I was actually addressing this warning generated by the OP:

Useless use of private variable in void context at...

(I should have made this explicit.) I certainly agree that either a while or a foreach loop would be preferable here. Unfortunately, neither of your suggested alternatives results in the same number of iterations as the original:

16:05 >perl -wE "my $c = 0; for (my $n = 3; $n >= 0; $n--) { ++$c; } s +ay $c;" 4 16:05 >perl -wE "my $c = 0; my $n = 3; while ($n--) { ++$c; } say $c;" 3 16:05 >perl -wE "my $c = 0; my $n = 3; for (1 .. $n) { ++$c; } say $c; +" 3 16:05 >

And since the loop is likely incomplete (see my comments regarding $outfile), we cannot be sure that $count won’t be used for something later on in the loop — in which case, the foreach version of the loop would provide the values in their reverse order. So the safest alternative is probably:

while ($count-- >= 0) {

Update 1: Except that the value of $count within this loop is always one less than its “proper” value.

Update 2: Upon reflection, I now realise that GrandFather’s alternative loops were not intended as equivalents to the original, but as corrections to it, since it’s most likely that the OP code meant to loop for exactly $count iterations. If so, I apologise to GrandFather for the misreading.

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: why i cant print reading hash table? by Athanasius
in thread why i cant print reading hash table? by waytoperl

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



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.