Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

We could reduce your question to: Why does using subroutines make code simple?

We are looking at two very different functions. It is logical to split them and keep two simple easy to debug blocks, rather than interleave them in a complex routine. Depending on the simplicity of the records going to <STDOUT> it may even be better to have the workers print directly. If the records are long and will not print as an atomic operation, or if there is post processing, then an publishing thread that gathers them and prints them keeps this work in one place.

Something like this looks very simple to me.

# some initialisation, queue building etc... my $shouty = threads->create('publish'); # This is the boss loop, dispatches to workers while (<>) { chomp; # I guess $work->enqueue $_; ) sub publish { while (my $out = $result->dequeue) { print "I got: $out\n"; }

Do you have an example where you read <STDIN> and the $result queue in the same code block, that is simpler?

Now if we need to add pre or post processing then it sits nicely in the dispatcher or publisher routine without being all mixed up.

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

In reply to Re^5: Threading with a twist by Random_Walk
in thread Threading with a twist by scorpion7

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 sharing their wisdom with the Monastery: (7)
As of 2024-04-24 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found