#!/usr/bin/perluse CGI;
print "Content-type:text/html\n\n";
print "<TABLE>\n";
@filetypes=("txt","jpg");
@realfiles;
opendir(IMD, "accounts/carniojack424/") ¦¦ die("Cannot open directory");
@thefiles= readdir(IMD);
closedir(IMD);foreach $ind (@thefiles)
{
my $count = ($ind =~ tr/\.//);my $doneyet=0;
my @ext=split($ind, /\./);
foreach(sort @filetypes)
{
if($_ eq $ext[1])
{
$doneyet=1;
}
}unless($ind eq "." ¦¦ $ind eq ".." ¦¦ $count >= 2 ¦¦ $doneyet == 0 ¦¦ $count <=0)
{
@realfiles=(@realfiles, $ind."<br>");
}}
@realfiles=sort (@realfiles);
@color=("\#FFE5A6","\#FFFFFF");
$currColor=0;foreach(sort @realfiles)
{
$done=0;
if($currColor == 0 && $done==0)
{
$currColor=1;
$done=1;
}
if($currColor == 1 && $done==0)
{
$currColor=0;
$done=1;
}
print "\n\t<TR>\n\t\t<TD style=\"background-color:".$color[$currColor]."\">\n\t\t\t" . $_ . "\n\t\t</TD>\n\t</TR>\n";
}print "\n</TABLE>";
For performance reasons I'd switch your loop around to check one regexp against all files, then change regexps, rather than the other way around. There's an initial hit on the first regexp since it has to be compiled.
It also looks like you're stripping out periods from the file, then trying to split on periods.
I'd put in a bunch of print statements, or run through the perl debugger to see where things are going wrong...
Sean
my $rows = 0;
foreach ... {
$color = $rows++ % 2;
...
}
You can rotate through as many colors as you want:
my $rows = 0;
my $color_count = 2;
foreach ... {
$color = $rows++ % $color_count;
...
}
You can have 3 rows one color then the next three rows another color:
my $rows = 0;
foreach ... {
use integer;
$color = $rows++/3 % 2;
...
}