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

Dearest Monks,

I feel like I should know this by now ... but how does one pass variables via a link to a perl script?

In php it's http://www.perlmonks.org/test.php?id=1 in order to pass the variable $id=1 to the test.php program.

This doesn't work in perl as far as I can tell. Is there a similar method.

chris

Replies are listed 'Best First'.
Re: Passing variables via internet links
by Arunbear (Prior) on Nov 19, 2006 at 22:35 UTC
    You can use the CGI module to access such parameters e.g.
    use CGI; my $query = CGI->new; my $id = $query->param('id');
    or
    use CGI qw/:standard/; my $id = param('id');
    Have you read ovid's tutorial on Web Programming Using Perl?

    update: I've assumed you'll be using a CGI script in which case you'd typically pass the parameter like:

    http://www.perlmonks.org/cgi-bin/test.cgi?id=1
      thanks! thought it'd be pretty easy! thanks also for the reference to the tutorial ...
Re: Passing variables via internet links
by davorg (Chancellor) on Nov 20, 2006 at 14:55 UTC
    In php it's http://www.perlmonks.org/test.php?id=1 in order to pass the variable $id=1 to the test.php program.

    I believe that this is only true if your PHP environment has "register_globals" turned on. And since PHP 4.2.0 this directive defaults to being turned off. It sounds like the PHP developers have finally realised what a huge security hole this presents (as explained by tinita).

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: Passing variables via internet links
by tinita (Parson) on Nov 20, 2006 at 10:34 UTC
    In php it's http://www.perlmonks.org/test.php?id=1 in order to pass the variable $id=1 to the test.php program. This doesn't work in perl as far as I can tell. Is there a similar method.
    and this is good!
    image you have a $very_important_variable in your script and someone passes very_important_variable=foo to your script.
    or you have $file_to_print and someone passes file_to_print=/etc/passwd or something like this.