Hello again skatpally,

Sorry for the late reply but I got busy with something else.

Regarding your question what I am looking is when the file is locked and multiple Perl commands are triggered. I want to know an approach where each of the commands is in the queue and each gets triggered one after another. I think the best solution to your problem is Thread::Queue.

More specifically you should read the Thread::Queue/ADVANCED METHODS. There you will find ways in checking/adding/altering the queue of you commands in a way you desire.

The link that I provided you contains an example of this module Re^3: perl script and queue. Any way, a more complete code example that could give you a close solution to what you desire is provided bellow.

Sample of executable code:

#!/usr/bin/perl use strict; use threads; use warnings; use feature 'say'; use Thread::Queue; sub executeCommands { my ($commands) = @_; say $commands; } my $q = Thread::Queue->new(); # A new empty queue # Set a size for a queue $q->limit = 5; # Worker thread my $thr = threads->create( sub { # Thread will loop until no more work while (defined(my $item = $q->dequeue())) { # Do work on $item executeCommands($item); } } ); my @commands = ("Command_1", "Command_2"); # Send work to the thread $q->enqueue(@commands); { lock($q); # Keep other threads from changing the queue's content +s my @secondary_commands = ("Command_3", "Command_4"); # Insert two items into the queue in the head $q->insert(-2, @secondary_commands); my $item = $q->peek(); # do something with the items in queue if desired if ($item eq "Command_3") { my @third_commands = ("Command_5", "Command_6"); # Insert two items into the queue just behind the peek $q->enqueue(@third_commands); } } # Queue is now unlocked # Signal that there is no more work to be sent $q->end(); # Join up with the thread when it finishes $thr->join(); __END__ $ perl test.pl Command_3 Command_4 Command_1 Command_2 Command_5 Command_6

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re^3: script should wait for another script to complete by thanos1983
in thread script should wait for another script to complete by skatpally

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.