meonkeys has asked for the wisdom of the Perl Monks concerning the following question:
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.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}) }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Easy way to run tests on many CGI params?
by chromatic (Archbishop) on Aug 31, 2000 at 01:28 UTC | |
by isotope (Deacon) on Aug 31, 2000 at 02:44 UTC | |
Re: Easy way to run tests on many CGI params?
by ncw (Friar) on Aug 31, 2000 at 01:25 UTC | |
by merlyn (Sage) on Aug 31, 2000 at 03:10 UTC | |
by ncw (Friar) on Aug 31, 2000 at 11:35 UTC | |
by merlyn (Sage) on Aug 31, 2000 at 14:37 UTC | |
RE: Easy way to run tests on many CGI params?
by geektron (Curate) on Aug 31, 2000 at 02:29 UTC | |
Re: Easy way to run tests on many CGI params?
by wardk (Deacon) on Aug 31, 2000 at 19:07 UTC |