Dear Monks,
The following is a cgi designed to upload a file and search and pull out individual case-id's from the rest of the mess. The file uploads are generally plaintext and html. Some get to be rather large, 5 megs or so. I have it working right now, but It will only return 1 case-id from a list of fifty. I suspect that the problem is in my choice of the $cases variable. However I'm not sure, just stuck in the mental mud.
Any one know how to retrieve all of the case-id's?
#!/usr/bin/perl -w ### Version ### ### 1.1.1 Working on file upload and loop ### 1.1.2 File will upload but pulls only 1 id ### muppet.cgi ### file based case id grabber ### use strict; use CGI qw/:standard/; ### Print HTML ### print header, start_html('The Muppet'), h1('Waka_W4k4!'); print_form() unless param; print_results() if param; print end_html; ### Sub Print Form ### ### Form Subset ### sub print_form { print start_multipart_form(), filefield(-name=>'payload',-size=>60),br, submit(-label=>'Upload File'), end_form; } ### Sub Print Results ### ### Do work and print results ### sub print_results { ### Payload Variables ### my $file = param('payload'); $file=~m/^.*(\\|\/)(.*)/; my $file_name = $2; my $upload_file = upload('payload'); my $upload_dir = "/var/www/html/abuse"; ### Check for File Upload ### if (!$file) { print "No file uploaded."; return; } ### Write Uploaded file to disk ### open UPLOADFILE, ">$upload_dir/$file_name"; while (<$upload_file>) { print UPLOADFILE; } close UPLOADFILE; ### Prepare the goods to be delivered ### my $goods = "/var/www/html/abuse/$file_name"; my $caseid = 'Case - '; my $cases; open GOODS, "$goods"; my @goods=<GOODS>; close GOODS; foreach(@goods){ if (s/$caseid//){ $cases = $_; } } ### Print the Relavent Information ### print h2('File Name'),$file_name; print h2('File MIME type'), uploadInfo($file)->{'Content-Type' +}; print h2('Cases'), $cases; print h2('<A HREF="muppet.cgi">Try Again</A>'); } ### End of Sub Print Results ### ### FIN ###

peace,
amearse

In reply to File upload and regex by amearse

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.