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: Beginner:
Here's another one...more involved

 



S_Shrum
User

Jan 22, 2001, 11:07 AM

Post #1 of 5 (430 views)
Here's another one...more involved Can't Post

The following code works great on my NT box but not on mt hosts Apache Unix box. All it does is scan the specified folder for a list of filenames and displays the files as links in a 2 column table. When the script is run on the Unix box I get an error message that there was a problem executing the directive.

Any help would be apprechiated.

Sean Shrum
sean@shrum.net

Code follows:

#!/usr/bin/perl

# Split the name-value pairs from the query string
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach (@pairs){
($name, $value) = split(/=/, $_);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$input{$name} = $value;
}

# open the user specified directory
opendir (DIR, "$input{'path'}") or die "Error opening the specified directory: $input{'path'} $!\n";;

# get all the filenames in the directory minus the '.', '..','.*'
@filenames = grep { $_ ne '.' and $_ ne '..' and $_ ne '_vti_cnf' } readdir DIR;

# close the directory
closedir(DIR);

# increment the number of filenames by 1
$numberoffiles = $#filenames + 1;

print "<table align=center><tr><td align=center><font size=6><b>Contents of '$ENV{'SERVER_NAME'}/$input{'path'}'</b></font></td></tr><tr><td align=center><font size=\"2\">$numberoffiles files currently housed in this folder</font></td></tr><tr><td> </td></tr>";

# display the filenames as links in a table
print "<table width = 100% border=0><tr>";

# display the filenames in a table
foreach (sort @filenames) {
print "<td align=center><a href=\"/$input{'path'}/$_\">$_</a></td>";
if ( $count % 2 ) {
print "</tr><tr>";
}
$count++;
}
print "</table>";



japhy
Enthusiast

Jan 22, 2001, 11:46 AM

Post #2 of 5 (427 views)
Re: Here's another one...more involved [In reply to] Can't Post

My guess is you're not able to open the directory like you're trying to. Check the error log.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


S_Shrum
User

Jan 22, 2001, 4:34 PM

Post #3 of 5 (420 views)
Re: Here's another one...more involved [In reply to] Can't Post

I checked the log after producing the error again...in short:

invalid CGI ref "/cgi-bin/contents.pl?path=soaring/photos" in /a/home/shrum/docs/soaring/photos/index.shtml

I check the perlguru archive and found another person with the problem but I am already doing the SSI call correctly in the page:

<!--#exec cgi="/cgi-bin/contents.pl?path=soaring/photos"-->

Any ideas?

Thanx again for all your help.

Sean Shrum
sean@shrum.net


rGeoffrey
User / Moderator

Jan 22, 2001, 8:54 PM

Post #4 of 5 (413 views)
Re: Here's another one...more involved [In reply to] Can't Post

"but I am already doing the SSI call correctly"

Unfortunately you are not. Let us borrow from Section 5.7 of the Mouse book (CGI Programming on the World Wide Web)...


Code
Remember we talked about query strings as a way of passing information to a CGI program in Chapter 2? 
Unfortunately, you cannot pass query information as part
of an SSI exec cgi directive. For example, you cannot do the following:

<!--#exec cgi="/cgi-bin/count_days.pl?4/1/96"-->

But the book does provide a way out...


Code
However, we can create a regular Perl program (not a CGI program) that takes a date as an argument, 
and calculates the number of days until/since that date:

<!--#exec cmd="/usr/local/bin/httpd_1.4.2/count_days.pl 4/1/96"-->

In the Perl script, we can access this command-line data (i.e., "4/1/96") through the @ARGV array.

It seems a major oversight in the rules for SSI, but it is what we have to live with.

---
Sun Sep 9, 2001 - 1:46:40 GMT, a very special second in the epoch. How will you celebrate?


S_Shrum
User

Jan 23, 2001, 1:19 PM

Post #5 of 5 (389 views)
Re: Here's another one...more involved [In reply to] Can't Post

Is this issue inheirent only on Unix or is it that NT is more lenient? As I stated before, the SSI calls works beautifully on my NT intranet box.

Thanx for the info.

Sean Shrum
sean@shrum.net


Sean Shrum
<a href="http://www.shrum.net">www.shrum.net</a>

 
 


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

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