I'm curious how all of you CGI whizpopmonks like to handle instances where you must check against a parameter that may not be defined, I find that a lot of my programming seems to run into the fact that when using strict, I get a lot of
"[Fri Oct 12 18:15:49 2001] form.cgi: Use of uninitialized value at /www/mako/dev/public_html/bin/form.cgi line 92." type of warnings. The following snippet builds a select for a form and I have defaults that I'd like to use but if the form has been called with parameters, use them instead. Note: $base_vars{'day'} is equal to todays date and $q->param('arrday') can be null (doesn't exist) or a day in the future.
my @days = (1..31);
my $days_select = '<select name="arrday"><option></option>';
for (@days) {
if ($q->param('arrday') && $q->param('arrday') == $_) {
$days_select .= "<option value=\"$_\" selected>$_</option>";
}
elsif ($base_vars{'day'} == $_ && $base_vars{'day'} > $q->param('arr
+day')) {
$days_select .= "<option value=\"$_\" selected>$_</option>";
}
else {
$days_select .= "<option value=\"$_\">$_</option>";
}
}
$days_select .= '</select>';
Could I get some suggestions on this? I'm tired of having error logs like 200mb's long {grin} kinda fine for development, not so fine for final code.
BlackJudas
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.