CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Table Format in PERL

 



okalani
New User

Mar 14, 2003, 1:07 PM

Post #1 of 2 (366 views)
Table Format in PERL Can't Post

Hello,

I need a solution to a problem that I'm having and I'm hoping someone can lend their expertise.

I created a script that will read a directory that contain images and display its contents onto a web page. Right now it dispalys the contents in a list format but I want it to dispaly in a table.

I want the contents displayed in a table that is 4 columns wide and the number of rows will depend on the number of images in the directory. Can someone show me how this can be acomplished?

Below is the code that I have. Also I'm new to all this can someone tell me if I wrote the codes correctly?

======= CODE BEGIN ========

#!/usr/bin/perl
use strict;
use CGI qw(:standard);

my $dir_name = param('dname');
my $header_title = param('htitle');

my $pics_path = '/home/test/public_html/pics';
my $pics_url = 'http://www.test.com/pics';
my $pics_dir = "$pics_path/$dir_name";

opendir(D, $pics_dir) || die;
my @pics=grep { !/^\./ and /\.JPG$/ } readdir D;
closedir(D);

print header,
start_html("$header_title"),
h1({-align=>'center'}, "$header_title"),
p;
print "These are my pictures: ";
foreach my $pics (@pics) {
print "<LI><a href=\"$pics_url/$dir_name/$pics\">$pics</a>";
}
print end html;

======= CODE ENDS =========

Thanks!


(This post was edited by okalani on Mar 14, 2003, 1:17 PM)


okalani
New User

Mar 14, 2003, 10:03 PM

Post #2 of 2 (358 views)
Re: [okalani] Table Format in PERL [In reply to] Can't Post

OK, I added the table to the script and it displays just fine if I wanted all the image links to be all in one row. But what I'm trying to do is allow only 4 columns per row. For example, if I have 5 images in my directory, 4 image links should be displayed in the first row which contains 4 columns and the 5th image link should break off and display on the second row and so on. In other words, the amount of rows will depend on how many images I have in a directory.

How can I acomplish this?

opendir(D, $pics_dir) || die;
my @pics=grep { !/^\./ and /\.JPG$/ } readdir D;
closedir(D);

my $count = @pics;

print header,
start_html("$header_title"),
h1({-align=>'center'}, "$header_title"),
p;
print "There are $count pics in this directory",
p;
print "<table width=\"500\" border=\"0\" align=\"center\">";
print "<tr>";
foreach my $pics (@pics) {
print "<td><a href=\"$pics_url/$dir_name/$pics\">$pics</a></td>";
}
print "</tr>";
print "</table>";
print end html;

Thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives