It isn't a surprise to you that the file "UPLOAD" doesn't exist and thus can't be opened on Line 17, right? Its a good idea esp. w/ us novices, it to comment every single goldurn close bracket w/ what its closing (even just 2 lines) e.g.
for my $file (sort grep /file/, param()) { print p(); my $handle = upload($file); open (IMAGE, ">$handle") || die "Couldn't open $handle: $!"; my $buffer; while (read($handle, $buffer, 10240)) { print IMAGE $buffer; } # while read or for my file sort ??? unless (defined($handle)) { if ($file =~ /(\d+)/) { print h3("File request $1 did not return a handle\n"); } # if $file =~ \d next; } # unless def $handle print p(), h3("Uploaded $handle"), br(), "<pre>"; print encode_entities($_) while <$handle>; print "</pre>"; } # for my $file sort
So, if handle isn't defined, why print to it? Why don't you have -w up there? How about sort grep /file\d+/ to get only the file0-9+ params? Why not put a few debugs in along the way: print STDERR "Trying file $file\n"; before the upload stmt. Maybe an "if (-s $file)" to be sure $file exists. As the tilly said, its not about getting this one to work, its about learning how to get scripts in general to work. You know UPLOAD isn't the file, so how did you get the name? From your for sort grep loop. What else is that returning? Use STDERR to put debug to the error logs so you can watch as the script progresses.

I like to use
print STDERR "trying file $file in forloop\n" if $debug > 3;
and then use "my $debug = X" as needed. You'll often find you need to turn debugging back on, and by using different levels for different levels of detail, you can leave all your debugs in (my $debug = 0) and turn on those you need as you change stuff.

a


In reply to Re: Re: Re (tilly) 1: Uploads (again!) by a
in thread Uploads (again!) by Stamp_Guy

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.