Can someone assist me in developing a script that, after processing an integer through the standard input eg. www.here.com/linker.pl?3 returns a specific page based on that integer? I noticed the perl monks page has a similar solution, is there any way to get the source code? Michael michaelw@cyberone.com.au

Replies are listed 'Best First'.
RE: Main linker script
by t0mas (Priest) on Jul 23, 2000 at 13:17 UTC
    You can download Everything at The Everything Development Company
    If you want to do it yourself, you probably want to use the CGI module, but if returning a specific page based on a integer is all you want to do, I would name my file 1.html, 2.html, 3.html, etc and skip the script ie. www.here.com/1 will display 1.html :)

    /brother t0mas
RE: Main linker script
by Russ (Deacon) on Jul 23, 2000 at 23:25 UTC
    Here's a quickie.
    #!/usr/bin/perl -Tw use strict; use CGI; my %Pages = (1 => sub {open FILE, 'frontpage.html'; print while <FILE>}, 2 => sub {open FILE, 'aboutus.html'; print while <FILE>}, 3 => sub {open FILE, 'login.html'; print while <FILE>}, 42 => \&showStats); my $Num = CGI::param('Num') || 1; #If we don't get a number, show the +front page print CGI::header(); &{$Pages{$Num}};
    Notes:
    • For brevity, I didn't check the return status of open, or close FILE. You should.
    • You would "call" this like: www.here.com/linker.pl?Num=2
    • Thanks to ar0n for reminding me to print CGI::header (I forgot it, at first)

    Russ
    Brainbench 'Most Valuable Professional' for Perl

      Ick, duplicated code. :) You can use a hash, but why not an array?
      my @pages = ( 'frontpage.html', 'aboutus.html', 'login.html', ); # extra comma is there so adding new pages is easier my $num = CGI::param('Num') || 1; page($num - 1); # or put a dummy at the start of @pages sub page { $| = 1; my $num = shift; if (open(FILE, $pages[$num])) { print while <FILE>; } }
      A hash would work too, but if you're using numeric offsets already...

      You could even make page 0 show stats.