Plumbing the depths of the code

Ovid on 2004-05-27T19:44:44

How annoying. The code doesn't have a clean way of doing 'X'. Therefore I need to add this feature. Hmm ... it appears that I need to add it in a Mason component that's not tested. That's even more annoying. Then the final annoyance: seeing, for the first time, the actual code that I must change.

  # push in first row (always the same as the default options)
  push(@{$advanced_options[0]}, @report_options);
  my $i = 1;
  my ($day_range_rev_option) = grep { $_->cgi_name =~ /day_range_rev/ } @options;
  @options = grep { $_->cgi_name !~ /day_range_rev/ } @options;
                                                                                                                            
  while (scalar @options > 0) {
    my @current_options = ();
    if (scalar @report_options >= 3) {
            @current_options = splice(@options, 0, 3);
            } else {
        @current_options = splice(@options, 0, scalar @options);
            }
    push(@{$advanced_options[$i++]}, @current_options);
        }
  push(@{$advanced_options[$i++]}, ($day_range_rev_option))
    if ($day_range_rev_option);

Um, yeah.

Update: As it turns out, after much puzzling over what was intended, it turns out that the while loop reduces down to this:

  while (@options) {
    push @advanced_options => [splice @options, 0, 3];
  }


List::Group

cwest on 2004-05-27T20:58:19

use List::Group qw[group];

my @advanced = group \@options, cols => 3; # rows => 3
For nice effect one might also try:
use HTML::Table;
my $table = HTML::Table->new(-data => \@advanced);

# elsewhere in some mason world

<% $table %>
Ah well...