Dear Perl experts,

I have created my first Perl script (I am a complete novice): it searches for certain files on a network disks according to the data from the parsed XML-file and then copies them to the working folder. Since it has to browse a lot of folders the waiting period is up to 1 minute. I would like to have a text cursor rotating while the process is going on.

Here is my subprogram:

sub spin { my ($arg) = @_; $|++; for (my $x = 0; $x <= $arg; ++$x){ foreach (("-", "\\", "|", "/")){ print $_; Time::HiRes::sleep (0.1); print "\b"; } } print " \n"; }

It works perfectly well by itself.

And here are the pieces of code themselves:

my $dir; my $pattern = $version; OUTER: foreach ( @list_level_top ) { my $name = "$_" . "/*"; my @list_level_current_version = (glob ($name)); foreach (@list_level_current_version) { if ($_ =~ /\Q$pattern/) { $dir = $_; last OUTER +; } } }

and this:

copy ("$source", "$destination") or die "Failed to copy setup file\n";

Is there any way to use the spin function while the process of searching and/or copying is going on? I have checked all the solutions both here and on other sites and could neither understand how it works nor implement: way too much complicated and fail to produce what I expect (or I do it the wrong way). I would like to find a simple and, which is more important, working solution.

Thank you in advance.


In reply to Spinning cursor while waiting for search/copy process to be finished by Ingvar

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.