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

I have a huge questionaire built in CGI that appends an error to $error each time a field isn't filled in.
if (!$q4b_inter) { $error .= "q4b Interoperability was missing<br>"; }
The form has just over 100 questions and if they miss most of them, I have a HUGE list of error messages that span the page. I was wondering if there was a way to separate the errors into three columns of equal size (except the last one might be one or two less than the others) so it wouldn't all be one huge VERTICLE error message.

I guess it would have to be in a table somehow. All errors have
at the end.

Any help would be much appreciated.

Replies are listed 'Best First'.
Re: Separating by threes
by ysth (Canon) on Nov 23, 2004 at 04:20 UTC
    Remove the <br>'s, replace $error .= with push @error, and:
    use CGI qw/:standard *table/; # ... print start_table; print Tr(td([splice @error, 0, 3])) while @error; print end_table;
Re: Separating by threes
by tachyon (Chancellor) on Nov 23, 2004 at 04:11 UTC

    Your guess about a table is spot on.....

    my $err = join "\n", map { "Error $_<br>" } 0..100; my @errs = split /<br>\s*/, $err; $err = qq!<table width="100%">\n!; for ( my $i=0; $i<@errs; $i+=3 ) { $err .= sprintf "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", map { defined $_ ? $_ : '' } @errs[$i..$i+2]; } $err .= "</table>\n"; print $err;

    You could save yourself the split by simply pushing the errors into the @errs array in the first place.

    cheers

    tachyon

Re: Separating by threes
by dws (Chancellor) on Nov 23, 2004 at 05:36 UTC

    The form has just over 100 questions and if they miss most of them, I have a HUGE list of error messages that span the page.

    Another approach is to use styles to color the missing questions red (and/or make the text bold). Then you can provide a single "Please fill in the missing fields" error. This is how I prefer to be directed, at least. Long strings of error messages often leave me with ill feelings towards whoever coded them.

Re: Separating by threes
by Anonymous Monk on Nov 23, 2004 at 03:59 UTC
    sorry, that was meant to read each error is separated by a BR tag.