in reply to Re: Re: CGI params
in thread CGI params

Unfortunately that didn't help, ...

Strange. I was able to duplicate your problem (by adding   use CGI qw(:standard); to the top of that fragment). The change I offer fixes the problem, at least does when I try it. What, exactly, does your code fragment look like when you try it?

Mine looks like this:

C:\test>type test.pl use CGI qw(:standard); # my %params = map ($_ => param('$_'),param()); my %params = map {$_ => param($_)} param(); print '-->' . $params{'listname'}. '<--' . "\n"; C:\test>perl test.pl listname=foo bar -->foo<--

Replies are listed 'Best First'.
Re: Re: Re: Re: CGI params
by Roger (Parson) on Sep 09, 2003 at 08:23 UTC
    The problem is with the single quote around '$_', which tells param to look for an exact match of '$_', not an element from the param list. If you take away the single quotes from the $_, the code should work fine.

    The reason for the code to display "bar" for "listname" is because the hash was not correctly constructed. The failed mapping created a hash: listname=>bar as a side effect.
Re: Re: Re: Re: CGI params
by devslashneil (Friar) on Sep 09, 2003 at 08:05 UTC
    Hrmm, mine looks very similar.
    use strict; use CGI qw/:standard/; use DBI; use Mail::Sendmail; use MIME::Lite; my $q = CGI::new(); my %params = map {$_ => param('$_')} param(); print '-->' . $params{'listname'}. '<--' . "\n";
    I am running this on a debian box however you seem to be using windows, i wonder if this is contributing as our code looks very similar.

    Neil Archibald
    - /dev/IT -
      I am running this on a debian box however you seem to be using windows, i wonder if this is contributing as our code looks very similar.

      I suspect that it has more to do with those single quotes. They're not the same as double quotes (think interpolation, or lack thereof). In this situation, single quotes do the wrong thing, and double quotes aren't needed.

      Sorry i misread, changing param('$_') to ($_) fixed the problem :) thanks heaps for your input

      Neil Archibald
      - /dev/IT -