I have a problem with printout in a small script I have written. It's something I have never seen before and I cannot see why it is happening.

The relevant code is as follows. (Everything before it is just input gathering)

for $station (@stations){ print "\n $station"; print OUTFILE "\n$station"; undef %found; splice @found; for $stage (@stages){ chdir "/opt/stc/db/$station/$stage/prod/doc"; @files = <MO*>; for $file (@files){ open HTMFILE, "< $file"; for $line (<HTMFILE>){ if ($line =~ /${monobj}/ && $line =~ /HREF/ && $line ! +~ /TOP/){ $found = $stage,$file"; $found{$found} = (split /-/, $line)[0]; } } close HTMFILE; } } @found = sort (keys %found); for $found (@found){ ($stage) = (split /,/, $found)[0]; print "\t- $stage - $found{$found}\n"; print OUTFILE ",$stage,$found{$found}\n"; } print "\n" if ($found[0] eq ""); print OUTFILE "\n" if ($found[0] eq ""); }
Any print statement within the 'for $station ...' loop is withheld until the start of the 'for $found ...' sub loop. So the line print "\n    $station"; right at the top does not print until the start of this last sub loop.

It's not a major issue. The printout looks exactly how I want it but it is bugging me. Since the @files can contain between 2000 and 3500 entries, it would be nice to have the value of $station printed out where I put it as this would give a better progress indication.

All suggestions gratefully received and tried.


In reply to Not printing when expected. by expatmark

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.