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

Why does this not work?

I call a script:
http://www.host.com/cgi-bin/script.pl?para_1=bla....

The script.pl is:
#!/usr/bin/perl -w use strict; use CGI qw(:standard); my @Co = (1,2); my $co; for $co(@Co) { my $param = param('para_$co'); # <-- ??? do_something($param); } ... ...
Is it not possible to have variables inside the param('xx') function?
Would be fine if anyone could help me (-:

Bye...
Georg

Replies are listed 'Best First'.
Re: CGI param problem
by Roger (Parson) on Nov 20, 2003 at 13:05 UTC
    Use double quotes if you want the variable $co to be interpolated.

    my $param = param("para_$co");
    And also you can drop that @Co bit too.
    foreach my $co (1..2) { my $param = param("para_$co"); do_something($param); }
      Oh my god...thank you!!!!!!!!!!
Re: CGI param problem
by l3nz (Friar) on Nov 20, 2003 at 14:12 UTC
    I'm almost blind with this monitor, but this looks like a simple typo. Maybe you need " instead of ' around
    my $param = param('para_$co');
    so that it's
    my $param = param("para_$co");
    hve not tried it, this is just a first look.

    While we're at it, I might suggest you to use a little more meaningful names and case discipline for your variables, too; it'll make debugging easier.