LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG-Webdev] Perl: counter for three columns

[ILUG-Webdev] Perl: counter for three columns

Thallophytic g0d hostyle at csn.ul.ie
Thu Dec 11 15:58:42 GMT 2003


On Thu, 11 Dec 2003, adam beecher wrote:

>
> # Hack to create two columns. Nasty perl but it's been a while.
> my $count = $#channels + 1;
> my $half = int($count / 2) + 1;
> my $counter = 0;
>
> # Open the table
> to_browser(qq{ <br /><table width="100%"><tr valign="top"><td
> width="50%"> });
>
> # for each channel, parse and display.
> foreach my $channel (@channels) {
>     $counter = $counter + 1;
>     if ( $counter == $half ) {
>         to_browser(qq{ </td><td width="50%"> });
>     }
>
>
> I'd like to change this to use three columns, which I guess I could do by
> dividing by three and adding one like yerman does above (doesn't perl have a
> modulus operator?), and then multiplying by two and yadda yadda, but I'd
> like to make a $columns var that I can adjust. Any hints for me?

Completely OTOH and untested, something like the following should do it.


my $columns = 3;
my $counter = 0;
my $width = 100 / $columns;


foreach my $channel (@channels) {
    $counter++;
    if ( $counter % $columns ) { # if there is a remainder
				 # add another cell
        to_browser(qq{ </td><td width="$width%"> });
    } else { # no remainder, end our row
        to_browser(qq{ </tr><tr> });
    }
}

Obviously the </tr><tr> isn't ideal ... but you should get the drift of it



More information about the Webdev mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell