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<--
| [reply] [d/l] [select] |
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.
| [reply] |
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 -
| [reply] [d/l] |
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.
| [reply] |
Sorry i misread, changing param('$_') to ($_) fixed the problem :) thanks heaps for your input
Neil Archibald
- /dev/IT -
| [reply] |
Yet dws is right. This works for me:
use CGI qw/:standard/;
my %params = map { $_ => scalar param($_) } param();
print '-->' . $params{'listname'}. '<--' . "\n";
Note that I added a "scalar".
The error was produced by three things:
- You're trying to use A => B as an expression for map, which doesn't work, as "=>" is actually a comma. So map only saw the "A" as the expression, and the "B" as the first item of the list fed to it.
- You used single quotes around "$_" which made CGI.pm look for the parameter "'$_'", literally, which doesn't exist. Combine that with...
- You used param() in a list context, which for a non-existing parameter produces an empty list. "scalar" fixes that.
So, in summary, you were filling %params with a list ( 'listname', 'wtf' ), as everything else dropped away.
| [reply] [d/l] [select] |