lakeTrout has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks,

I have my hands on some OLD perl and have a question. It's a CGI that spits out a report from a flat file. Everything was put in this flat file via brute force, like so:

print LOGFILE ("$FORM{filedNameFoo}\t");

That's just great for single entries like textboxes, but I have a few instances of checkboxes and I want to add a comma between them if they are true. I tried the following:

("$FORM{filedNameFoo},\t");

But when it's printed using this:
<tr class='white'><td valign="top"><b>Foo</b></td> <td>$fields[22] $fields[23] $fields[24] $fields[25] $fields[26]</t +d> </tr>

Of course I would get results like: foo,,,bar,,raz, etc -- can anyone help me with where/how to put a conditional to only print the comma if true? I've been away from the perl game for a long time, so please bare with me. Thanks!

LakeTrout

Replies are listed 'Best First'.
Re: Validate before printing to logfile
by roboticus (Chancellor) on Nov 28, 2007 at 23:01 UTC
    lakeTrout:

    If you have your checkbox values stored in an array, you could use something like:

    print join(",", grep { <cond_expr> ) @ValArray));
    HTH

    ...roboticus

      Thanks HTH,

      they are not stored in an array, but seems logical and easy to do so. I just might try that. Thank you!