ellem has asked for the wisdom of the Perl Monks concerning the following question:

I have no code (really) written yet I am just trying to understand the process(es) I am about to get involved in.

I want CGI to create a web page on the fly based on the contents of a directory local to the webserver and make buttons that correspond to the files for downloading/viewing. The Web Server is a Domino 5.0.8 server, the OS is NT4 SP5. I currently do this in Notes and it is fairly secure but it is bulky and frankly I'm not so sure I want to make Notes dance anymore (read Lotus Script is no fun and Formula language is making me insane.) So I thought, "Hey the rest of the planet uses this crazy CGI; why not me?"

Here's where my troubles start though -- I don't understand how to tell the CGI.pm how do do things I haven't already told it. Like;

print p ("How many scoops? ", popup_menu ("scoops", [1..5])) ;

I have told (well Randal Schwartz told) scoops that it would contain 1, 2, 3, 4, 5. I need 1..5 to be generated when the user hits the page. I need the script to read the directory at that time. I don't know how to make things happen when requested. I could proabably setup a DB (MySQL?) and have the CGI script read the DB table that contains the contents of the directory but that seems like an extra step or two.

Clearly I am confused. help?
--
lmoran@wtsgSPAM.com
print "\x{263a}"

Replies are listed 'Best First'.
Re: Perl...CGI...Things I want to do
by Zaxo (Archbishop) on Oct 05, 2001 at 01:37 UTC

    You need to learn some HTML as well as Perl and CGI.pm. One recommended starting point is Ovid's CGI Course. To get you going with code, start your cgi program like this:

    #!/usr/bin/perl -wT use strict; use CGI;
    The -wT flags tuurn on warnings and taint mode. It is a pain in the neck sometimes, but it will save you time and grief. The 'use strict;' line has a similar purpose. The 'use CGI;' is to save you work and avoid pitfalls. It's uses are covered in 'perldoc CGI'.

    You can find lots of help by browsing the Tutorials and Outside Links pages here.

    After Compline,
    Zaxo

      Thanks for the links!
      --
      lmoran@wtsgSPAM.com
      print "\x{263a}"
Re: Perl...CGI...Things I want to do
by George_Sherston (Vicar) on Oct 05, 2001 at 02:14 UTC
    Forgive me if I've misunderstood what you're trying to do, but the following would yield an array of all the files (and directories) in a given directory:
    my $path = 'yourdir/yoursubdir/'; # or whatever my @filearray; while (<$path*>) { s/$path//; # strip off the filepath push @filearray, $_; # push the filename into the array }
    You can then use the array to generate the form fields on your page. If you wanted to get only files with, for example, extension .txt, you would use <$path*.txt>

    (By the way, if you are new to perl - and I must say I only learnt this stuff a couple of months ago - you may wish to be reassured that the snippet above comes to much the same as
    while (my $file = <$path*>) { $file =~ s/$path//; push @filearray, $file; }
    ... though if you knew that already... well silly me.)

    Sorry this is not a comprehensive solution: I hope it's some help.

    § George Sherston
      You've helped more than you know... you just shoved me in the right direction.
      --
      lmoran@wtsgSPAM.com
      print "\x{263a}"
Re: Perl...CGI...Things I want to do
by ronzomckelvey (Acolyte) on Oct 24, 2001 at 09:02 UTC
    Hi

    I've got a nice Perl program that you give it a directory, it creates a web page based on the contents of the directory, with sub folders for the directories.

    All the config is done thru a web page, all just one proggie, even a feddback page.

    I created this for our users, who just copy files to a smb share, and like magic, they show up on a web page.

    ronzo

      May I see it?

      Chalmers: Aurora Borealis? At this time of year? A this time of day?In this part of the country? Localized entirely within your kitchen?
      Skinner: Yes.
      Chalmers: May I see it?
      Skinner: Oh, erm... No.

      --
      lmoran@wtsgSPAM.com
      print "\x{263a}"