Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Minor print_cat logic bug

Quote Reply
Minor print_cat logic bug
Minor logic formatting bug in the print_cat routine:

I don't know if this is in the 'stock' routine, or if it's been created
by all the various versions, but it affects formatting of tables/columns.

If you use several levels of nested tables, getting them to format properly
is sometimes aesthetically difficult.

To that end, I added a 'wdith' tag to the column parameters of the print_cat,
but that didn't solve everything, in fact, it showed another bug.

First, add the following to the top of the routine:


my $width = int (100 / $LINKS{build_category_columns}) ;
$width = 'width=' . $width .'%';

Then, where the start table code is, add $width to the string:


$output = qq|<div class="margin"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="catlist" $width valign="top">\n
|;

When you hit the following code, you see the bug. $i starts out as 0. That
is always false. It forces the second part of the main clause to print, and
you end up with a second column. You want to check if $i is _not_ 0 -- if it
is zero, just fall through. (ie: !$i if $i is zero is "TRUE")


# We check to see if we are half way through, if so we stop this table cell
# and begin a new one (this lets us have category names in two columns).
(!$i or ($i % $breakpoint)) or ($output .= qq|</td><td class="catlist" $width valign="top">\n|);
$i++;



The "bug" is the part:
($i and ($i % $breakpoint)) or ($output .= qq|</td><td class="catlist" valign="top">\n|);

What happens, is if $i is 0,the first part of the whole expression evaluates to "false" so the second part of the 'or' is done -- ie: an empty column is printed out.

The logic is ugly.... but the modified version works with complicated nested tables, while the original version doesn't --. My $width mod, allows the columns to be the same size, rather than randomly formatted.

I hate logic, it's so unforgiving!

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Subject Author Views Date
Thread Minor print_cat logic bug pugdog 3252 Oct 31, 2000, 1:03 PM
Thread Re: Minor print_cat logic bug
Stealth 3140 Oct 31, 2000, 1:09 PM
Post Re: Minor print_cat logic bug
pugdog 3151 Oct 31, 2000, 3:30 PM