Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

The weirdest thing....

by perlNinny (Beadle)
on May 09, 2007 at 20:54 UTC ( #614490=perlquestion: print w/replies, xml ) Need Help??

perlNinny has asked for the wisdom of the Perl Monks concerning the following question:

I have some perl code that calls cmd. I get the exitcode and if its a core dump, I print 'BAD' before the file name that caused the dump, otherwise I print the results. What I have found out is that the bad files will print all in a bunch at the end of the output and not interspaced within as I expected. What'z going on!?

Replies are listed 'Best First'.
Re: The weirdest thing....
by Corion (Patriarch) on May 09, 2007 at 21:01 UTC

    Without seeing any of your code it's hard to tell. Most likely you are Suffering from Buffering though.

    If the advice given by Dominus doesn't help you, maybe you can post a minimal code example that exhibits the problem.

Re: The weirdest thing....
by former33t (Scribe) on May 09, 2007 at 21:07 UTC
    I'm guessing you need to flush STDOUT.

    $|++;

      I'm nitpicking here, but note that $|++ does not increment $| when it's 1. $| is always 1 (flush) or 0 (buffer).

      That means that:

      # INCORRECT sub something { $|++; # do something without buffering $|--; }
      Will turn on buffering even if it was off before calling the subroutine.

      Usually that's not really a problem, but if you need to revert autoflush to its previous setting, you have to remember its status yourself:

      #CORRECT sub something { my $flush = $|++; # do something without buffering $| = $flush; }
        #CORRECT sub something { local $| = 1; # do something with autoflushing }
        Yes, of course you are correct. It's probably even a smidgen faster to just assign a 1 to $| than it is to perform the computation involved in incrementing. I don't think I've ever run into a situation where I wanted autoflush on a filehandle sometimes and then go back to buffering, but I'll keep that in mind.

        I do like the use of setting the autoflush locally in your other post.

        I'm nitpicking here, but note that $|++ does not increment $| when it's 1. $| is always 1 (flush) or 0 (buffer).

        You can use =1 instead of ++ and you wouldn't have to explain this. Be nice to your reader and use =1.

Re: The weirdest thing....
by jdporter (Chancellor) on May 09, 2007 at 21:23 UTC

    You have a bug on line 42.

      What do you mean; African or European bug?

      --
      tbone1, YAPS (Yet Another Perl Schlub)
      And remember, if he succeeds, so what.
      - Chick McGee

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://614490]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-08-19 16:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?