Hello 1nickt,

You are right, the OP never stated that he is using MySQL so I will update the answer.

Regarding Using a queue for this situation is quite sensible, in theory. Can you explain how to implement one with Thread::Queue? I would approach it like this. Example not real time code:

I use forks instead of threads because I get the error:

$ perl test.pl 1 2 This Perl not built to support threads Compilation failed in require at test.pl line 3. BEGIN failed--compilation aborted at test.pl line 3.

Having said that, sample of executable code:

#! /usr/bin/perl use forks; use strict; use warnings; use Thread::Queue; use feature 'say'; sub insert_to_db { say $_[0]; } my $q = Thread::Queue->new(); # A new empty queue # Send work to the threads $q->enqueue($_) for @ARGV; # Worker threads my $thread_limit = 8; my @thr = map { threads->create(sub { while (defined (my $item = $q->dequeue_nb())) { insert_to_db($item); } }); } 1..$thread_limit; # terminate. $_->join() for @thr; __END__ $ perl test.pl 1 2 Argument "2.56_01" isn't numeric in numeric ge (>=) at /home/user/perl +5/lib/perl5/x86_64-linux/forks.pm line 1570. 1 2

Of course the sample of code, in reality instead of ARG I would queue the number of insert statements and execute them in sequence.

Any way, my approach would be to queue the insert statements in order to complete each insert before the next one.

Hope this clears things more, BR.

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

In reply to Re^3: perl script and queue by thanos1983
in thread perl script and queue by k_manimuthu

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.