Although other people have shown you different ways in which to be multithreaded, I'd like to point out that the task you mentioned (FTP with hashmark printing) does not sound like something where you need or even want multithreading at all.

Multithreading is necessary when you need separate computations to happen at the same time (e.g. on a multi-cpu machine) (*). Multithreading is occasionally useful when you have to monitor multiple different input streams or monitor an input stream while doing some complex calculations in the background. (Some people just don't like writing state machines or using POE) The problem you mention sounds nothing like either of these cases.

To approach the problem you mentioned, it seems to that the matter is simple: pull down some of the file, see if you've pulled down enough bytes to write another '#' mark, print it if so, and repeat. Of course, if you're using Net::FTP to pull the file down (you aren't rewriting your own ftp protocol, are you?) then another poster already mentioned the option that'll do that for you. If you're running an external ftp program in the background, I'd suggest that you need to read perlipc and consider inter-process communication, and then check if your ftp program has the ability to print out hash marks as it's working (many do).

(*) Yes, I'm aware that multithreading per se isn't the only way to split computations across multiple CPUs; obviously one can run entirely separate processes.

-- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

In reply to Re: multithreading sample by fizbin
in thread multithreading sample by sashac88

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.