Click to See Complete Forum and Search --> : Perl for Intranet - How to list Dir contents?
SimonWray
08-15-2006, 09:48 AM
Hi
I've recently installed Apache2.2 and mod_perl5.8. I want to use it for dynamically listing the contents and status of various network files that contain in-house documentation.
So... where do I start? I'm ok with HTML, a bit of JS and am a VB6 programmer by trade, but I don't really know how to build Perl & Apache into an HTML document.
Ideally I'd like a test HTML page that illustrates how I reference Perl and get a directory listing from it. How do I know which module I want and do I need to reference them separately? do I distinguish the properties and directives (sp?) on them?
Thanks for any and all help.
Simon
PineSolPirate
08-15-2006, 03:37 PM
Most of the items you're looking for are either built-in or part of the core modules (same diff really :))
For directory work you'll need opendir, readdir, and their kin.
http://perldoc.perl.org/functions/readdir.html
For doing nice output to browsers you'd use the CGI module.
http://perldoc.perl.org/CGI.html
http://www.webmonkey.com/webmonkey/98/47/index2a_page9.html?tw=programming
Hope that helps out a bit. PHP also has some nice directory functions, I only mention it because it was easier for me to learn PHP than Perl, though Perl isn't too bad.
You could use something like below for full directory recursion.#!/usr/bin/perl
use strict;
use File::Find;
use CGI ':standard';
use warnings FATAL => 'all';
use CGI::Carp 'fatalsToBrowser';
@_ = qw(../htdocs/) unless @_;
my $t = "Directory Map for $_[0]";
print header,
start_html($t),
h1($t);
find sub { print $File::Find::name, -d && '/', br }, @_;
print end_html;
SimonWray
08-29-2006, 08:11 AM
Thanks for the info.
CyCo: I have put your script into a text file, renamed it as .pl, put it into my /perl directory (within Apache2.2 directory) and then run firefox over it... but I recieve an error:
"Directory Map for Apache2::RequestRec=SCALAR(0x1bad8a4)
Software error:
Can't stat Apache2::RequestRec=SCALAR(0x1bad8a4): No such file or directory
at (eval 64) line 18"
Any suggestions as to what I've done wrong?
I'm totally unfamiliar with Perl and how I should even be trying to execute this script. Have I missed out some html-required formatting? i assumed that the "start_html" and "end_html" functions might have done this.
Thanks
SimonWray
08-29-2006, 09:28 AM
I've managed to get it working...
The problem appears to be this line;
@_ = qw(../htdocs/) unless @_;
I can amend this to be;
@_ = "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs";
and the script works fine. Perl/Apache appears to dislike both the use of qw() and the unless expression - i've tried removing either of them and only when I remove both does the script run...
It must be mod_perl related, because I tested it on my local server which consists of Apache 2.0.54 (Win32) & Perl 5.8.6
It ran just the same on my hosted server: OS Linux, Apache 1.3.34 (Unix) & Perl 5.8.7 with a minor change:
@_ = qw(/home/topsecret/public_html/) unless @_;
Anyway, you've sorted it out, it seems. ;)
SimonWray
09-04-2006, 08:45 AM
Is there any reason why this script won't run over a mapped network drive?
#!/usr/bin/perl
use strict;
use File::Find;
use CGI ':standard';
use warnings FATAL => 'all';
use CGI::Carp 'fatalsToBrowser';
@_ = "//srv00128/uuw/IRIS/DevelopersPortal/Database Diagrams";
my $t = "Directory Map for $_[0]";
print "Content-type: text/html\n\n";
print "<HTML><BODY>";
print "$t";
print "<UL>";
find sub { print $File::Find::name, -d && '/', br }, @_;
print "</UL></BODY></HTML>";
I've tried variations of "//srv00128/uuw/IRIS/DevelopersPortal/Database Diagrams", with backslashes, but I receive errors such as;
Mon Sep 04 13:31:15 2006] [error] Unrecognized escape \\W passed through at (eval 53) line 11.\n
[Mon Sep 04 13:31:33 2006] [error] Unrecognized escape \\s passed through at (eval 54) line 11.\n
[Mon Sep 04 13:31:35 2006] [error] Unrecognized escape \\s passed through at (eval 55) line 11.\n
[Mon Sep 04 13:38:26 2006] [error] Unrecognized escape \\I passed through at (eval 56) line 11.\n
[Mon Sep 04 13:39:52 2006] [error] Unrecognized escape \\D passed through at (eval 57) line 11.\n
[Mon Sep 04 13:40:31 2006] [error] [Mon Sep 4 13:40:31 2006] -e: Can't stat srv00128/uuw/IRIS/DevelopersPortal/Database Diagrams: No such file or directory\n[Mon Sep 4 13:40:31 2006] -e: at (eval 58) line 19\n
[Mon Sep 04 13:41:19 2006] [error] [Mon Sep 4 13:41:19 2006] -e: Can't stat //srv00128/uuw/IRIS/DevelopersPortal/Database Diagrams: No such file or directory\n[Mon Sep 4 13:41:19 2006] -e: at (eval 59) line 19\n
The network drive is mapped on my machine as 'Q', which is actually "srv00128\uuw", but I can't get this script to run over any file on this drive. I have no trouble in running it over my C drive.
Where have I gone wrong?!
Thanks
Simon