Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Validate before printing to logfile

by lakeTrout (Scribe)
on Nov 28, 2007 at 22:41 UTC ( [id://653696]=perlquestion: print w/replies, xml ) Need Help??

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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://653696]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-18 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found