Hello,

I'd like to loop through the form elements submitted to a cgi script and take different actions depending on the input type of the form element. Actually, I only need to tell the difference between input type = "file" and input type = "anything else". Is there a way to detect the input type of a param in CGI.pm? Basically, the trick is that I am trying to write a general pre-processing script that could be used with a number of different forms, so I don't want to rely on knowing the names of the input elements that have type = file.

Here's the rough outline of code for what I'm trying to do:

$query = CGI->new; @params = $query->param; foreach my $p (@params) { if( [$p is a file handle/input type == "file"] ) { [ read in from the file and do some stuff ] } else { [ do some other stuff ] } }

Thanks for your help!!


In reply to Detect input type = file with CGI.pm by manta

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.