You might not want to suggest to others to use that bit of code. Slurping an entire uploaded file into a scalar is a Bad Thing(Anyone know of a trademark on this? {grin}). What if I want to upload a 10MB file? You're going to have to hold 10MB in memory. Bad. Instead, you should be using something like this, dealing with one line at a time:

my $file = $cgi->param('datei'); my $fh = $cgi->upload('datei'); while (my $text = <$fh>) { # Do something... like this maybe: print $out_file $text; }

You might even want to consider looking at read() to read in a specific number of bytes on each pass through the loop. I generally don't go as far as to do that though. So what if my binary uploads might slurp a little more if there's a large chunk of fle with no newlines in it? :) (P.S: I won't even pretend to know how frequently newlines appear in a binary file. All I know is that they are there.)


If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, reply to this node or /msg me to tell me what is wrong with the post, so that I may update the node to the best of my ability. If you do not inform me as to why the post deserved a downvote, your vote does not have any significance and will be disregarded.


In reply to Re^2: CGI upload and mod_perl by Coruscate
in thread CGI upload and mod_perl by physi

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.