Hello alenaustin,
Welcome to the Monastery. A possible solution to your problem could be Thread::Queue.
A "similar question" was asked in the past script should wait for another script to complete which contains several approaches in resolving the problem. On of those is:
#!/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
Maybe in your case there are not scripts to be executed but files to be processed, but the concept of the solution to the problem remains the same.
Hope this helps, BR.
In reply to Re: how to run a specific file from a list of filenames in a folder
by thanos1983
in thread how to run a specific file from a list of filenames in a folder
by alenaustin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |