I have come up with a way to display the progress of the downloading of a file, but it requires resorting to shell script instead of Perl; a technique I often receive down votes for when I suggest it to others. I am assuming these down votes are deserved and therefore I am reaching out for advice on how to implement a "download progress display" in a cgi script without sorting to shell scripting. Here's the bit of code I use to get the initial size of the download. I couldn't figure out get this key piece of information via WWW::Mechanize or LWP. In this snippet I resort to "shelling out" to wget which will tell me the size of the ZIP file I want to download. I couldn't figure out how to do this in pure Perl.
if ( $download_status eq "START" ) { my $wgetcmd = "wget -o $download_log -O $zipfile -b $zipurl"; system ( $wgetcmd ) == 0 or die __FILE__ . " [" . __LINE__ . "] cannot execute $wgetcmd : +$!\n"; sleep 1; my $shell_out = <<`SHELL`; grep Length $download_log | awk '{print \$3}' SHELL $download_size = $shell_out; }
Later on in the script I set a cookie to maintain the state of the download. If the download is not complete I simply "shell out" to grep awk and tail of the wget log file to get the status of the download. I hope there is a Monk that can help with my bad habits.

In reply to Help keep me from "shelling out" - download progress bar in cgi by Plankton

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.