Dear Perlmonks--
I humbly request assistance with somewhat trivial matters.

I'm trying to do a bunch of stuff with a list of cgi parameters. What I'm trying to do here
use CGI; use Text::CSV_XS; my %param; foreach my $field ($cgi->param) { $param{ $field } = $cgi->param( $field ); $param{ $field } =~ s/^\s+|\s+$//g; } my $outfile = './work_request.csv'; if ($param{mode} eq 'submit') { my $result = check_all(); if ($result eq 'ok') { $csv = Text::CSV_XS->new({ 'always_quote' => 1 }); @request = ($param{title} ,$param{requester} ,$param{department} ,$param{date_requested} ,$param{proposed_completion} ,$param{emergency} ,$param{work_around} ,$param{situation} ,$param{solution} ,($param{B01} || 0) ,($param{B02} || 0) ,($param{B03} || 0) ,($param{B04} || 0) ,($param{B05} || 0) ,($param{B06} || 0) ,$param{benefits}); $csv->combine(@request); my $line = $csv->string; # $csv->print($outfile, $line) # this is how I should be writi +ng the file # but it demands an arrayref (? +) my $fh = new IO::File ">> $outfile"; if (defined $fh) { print $fh ($line); $fh->close; } } } sub check_all { $result = 'ok' if ($param{title} ,$param{requester} ,$param{department} ,$param{date_requested} ,$param{proposed_completion} ,$param{emergency} ,$param{work_around} ,$param{situation} ,$param{solution} ,($param{B01} || $param{B02} || $param{B03} || $param{B04} || $param{B05} || $param{B06}) ,$param{benefits}) }
is check to make sure all parameters are present, including one of B01-B06, then write CSV to a file. I don't understand why $result always gets assigned the value "ok", and I can't get the output in a file.

Also, how can I incorporate a complex data structure, ie: putting all the params in a hash of hashes and run tests on that?

In reply to Easy way to run tests on many CGI params? by meonkeys

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.