HELP Please - I have hit a wall in trying to get the following perl created web page to work correctly. It is designed to find all the pictures (.jpg) in all folders below the designated one and to then display them in individual slideshows. I have a version of the page running succesfully by using html and javascipt (I define the picture directories) but can not translate the slideshow element to be written by perl. The full script I have is below:

#Start with the Directories

$pat = "images/Photos/";
opendir THEDIR, $pat;
@alldirs = readdir THEDIR;
closedir THEDIR;

# Print HTTP header and opening HTML tags.
print "Content-type: text/html\n\n";
print "<HTML><HEAD>\n";
print "<script type=\"text/javascript\">\n";
print "<!--\n";

# Next is files in each Directory
foreach $d (@alldirs) {
    $pat = "images/Photos/$d";
    if (length($d) > 3){
        opendir THEDIR, $pat ;
        @allfiles = readdir THEDIR;
        closedir THEDIR;
        $x=0;
        foreach $i (@allfiles) {
            if ($i =~ "jpg") {
                $x++;
                print "var $d$x=new Image()\n";
                print "$d$x.src=\"$pat/$i\"\n";
            }# end if
        }# end foreach
            push (@count, $d);
            push (@count, $x)
    }#end if
}#end foreach
print "</script>\n";

print "</HEAD>\n";
print "<BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>\n";


print <<"centerbit";
<table align=center border="0" width="720" cellspacing="0" cellpadding="0" height="100%" id="table1">
        <tr bgcolor=#0D0657 height=100>
            <td align=center><b>
    <font face="Arial" color="#FFFFFF" size="7">Company Name</font></b></p>
    <p align="center">
    <font face="Arial" color="#FFFFFF">What they do</font></td>
        </tr>
        <tr>
            <td><br><br><b>
    <font face="Arial" color="#0D0657">Previous Work<br></font></b>
            <table border="0" width="100%" id="table2">
                <tr>
centerbit

# Set up the Photos
$c = $#count;
$z = 0;
$y = 1;
while ($z < $c+1){
    $nam = @count[$z];
    $photo = substr($nam, 0, - 1).1;
    $var = substr($nam, 0, - 1);
    $nr = @count[$z+1];
    print "<td valign=top width=50% align=center><p><b><font face='Arial' size='2' color='#0D0657'>$nam</font></b></p>\n";
    print "<img src=\"../images/Photos/$nam/$photo.jpg\" name=\"$nam\" height=\"250\""; 
    print "onmouseover=\"this.height=400\" onmouseout=\"this.height=250\">\n";
    print "</td><td>&nbsp;</td>\n";
    if ($y == 2){
        print "</tr><tr><td colspan=2>&nbsp;</td></tr><tr>\n";
        $y=0;
    }#end if
    $z+=2;
    $y++;   
}#end while
print "</tr><tr><td colspan=2>&nbsp;</td></tr>\n";

#Do the slide script
$z = 0;
while ($z < $c+1){
        $nam = @count[$z];
        $pic = substr($nam, 0, -1);
        $var = substr($nam, 0, 4); # gives first 4 of photo name
        $cou = @count[$z+1];
                print "<script>\n";
                print "<!--\n";
                print "//variable that will increment through the images\n";
                print "var $var=1\n";
                print "function slide$var() {\n";
                print "//if browser does not support the image object, exit.\n";
                print "if (!document.images)\n";
                print "return\n";
                print "document.images.$nam.src=eval(\"$pic\"+$var+\".src\")\n";
                print "if ($var<$cou)\n";
                print "$var++\n";
                print "else\n";
                print "$var=1\n";
                print "//call function \"slideit()\" every 5 seconds\n";
                print "setTimeout(\"slide$var()\",5000)\n";
                print "}\n";
                print "slide$var()\n";
                print "</script>\n";
            $z+=2;  

}#end while

print <<"botbit";


        <tr bgcolor=#0D0657 height=100>
            <td align=center colspan=3><b>
        <font color="#FFFFFF" face="Arial">HONESTY IS OUR POLICY</font></b><br>
        <br>
        <b><font face="Arial" color="#FFFFFF" size="2"><a href="index.htm">
        <font color="#FFFFFF">HOME</font></a>&nbsp;&nbsp;&nbsp; <a href="gallery.pl">
        <font color="#FFFFFF">GALLERY</font></a>&nbsp;&nbsp;&nbsp; <a href="testimonial.htm">
        <font color="#FFFFFF">TESTIMONIALS</font></a></font></b></p>
        <p align="center">
        <font face="Arial" size="2" color="#FFFFFF">Contact 
    them :
    T: Telephone Number(s)&nbsp;&nbsp;
    M: Mobile Number(s)&nbsp;&nbsp;
        E:
        <a href="mailto:contact@companyname?subject=Contact from Website">
        <font color="#FFFFFF">contact\@companyname</font></a></font></td>
        </tr>
    </table>
</body>

</html>
botbit

Some quick questions: is this unix or windows? You have no directive for either on the first line (#!). Is the script executable by the web server? What error message are you getting (look in the web server error log)? What happens when you run the script at the command-line? Can you sudo to the web server user and try to runt he script?

What is this supposed to do?

$c = $#count;

That sets $c = 0 every time because # is a comment tag. If you're trying to get the count of what's in the array, use:

$c=@count;

Which will tell you how many elements are in an array in perl.

Some quick questions: is this unix or windows? You have no directive for either on the first line (#!). Is the script executable by the web server? What error message are you getting (look in the web server error log)? What happens when you run the script at the command-line? Can you sudo to the web server user and try to runt he script?

This is running on a Wintel platform using Sambar Server v7. I get no errors from the server, only in the browser where it is telling me that I have a java error where the line reads (when run) 'document.images.Bathrooms.src=eval("Bathroom"+Bath+".src")'. To see the javascript running from a straight html page go to http://www.tautbyron.com/gallery.pl which has the first functionality of reading from the directories done by Perl but then has a seperately written java function for each of the slide shows. It is this piece that I am trying to get perl to output correctly.

What is this supposed to do?

$c = $#count;

That sets $c = 0 every time because # is a comment tag. If you're trying to get the count of what's in the array, use:

$c=@count;

Which will tell you how many elements are in an array in perl.

Thanks - that appears to have been the problem as code now running fine.

Thanks - that appears to have been the problem as code now running fine.

No it didn't. It generated an error and so the previous page re-ran.

I got it to work fine. I put in the first line

#!/usr/bin/perl

and changed the line I spoke of. Then, I changed the path to:

print "<img src=\"./images/Photos/$nam\" name=\"$nam\" height=\"250\"";

What error are you getting? Because mine is running just fine now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.