in reply to Simplifying repetitive flow structures

I think the problem is that you're trying to build the Tr all at once. Use the conditionals to determine your branching, and leave the stuff that's not conditional (e.g. $ref->{'loc'}) outside of the if blocks. Construct the Tr after you've figured out what it's made of.

The below code doesn't exactly reproduce the functionality of your code, but it's probably good enough (or can be adjusted).

my @tds = (); if ($ref->{'pic'}) { push @tds, $q->a({href=>"$ref->{'pic'}"},$ref->{'name'}); } else { push @tds, "<LI>".$ref->{'name'}; } push @tds, $ref->{'phone'}; if ($type eq 'f' || $type eq 'c') { push @tds, $ref->{'fax'}; } else { push @tds, $ref->{'cell'}; } push @tds, $ref->{'loc'}; if ($type eq 'c') { push @tds, $ref->{'con'}; } else { push @tds, $q->a({href=>"mailto:$ref->{'email'}"},$ref->{'email'}) +; } print $q->Tr([$q->td({-bgcolor=>$cellcolor},\@tds)]);

Replies are listed 'Best First'.
Re: Re: Simplifying repetitive flow structures
by Dogma (Pilgrim) on Apr 04, 2002 at 06:23 UTC
    I think is a much better and maintainable way of doing things. I can even adjust the table headers by evaluating the array in a scalar context. Great Idea, Thanks!