Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Re: CGI params

by devslashneil (Friar)
on Sep 09, 2003 at 07:43 UTC ( [id://289957]=note: print w/replies, xml ) Need Help??


in reply to Re: CGI params
in thread CGI params

Unfortunately that didn't help, thanks for the input though, it's a really confusing error, the only thing i can think of is that it's trying to evaluate param() as a hash?

Neil Archibald
- /dev/IT -

Replies are listed 'Best First'.
Re: Re: Re: CGI params
by dws (Chancellor) on Sep 09, 2003 at 07:48 UTC
    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<--
      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.
      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 -
Re: Re: Re: CGI params
by bart (Canon) on Sep 09, 2003 at 13:24 UTC
    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:
    1. 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.
    2. You used single quotes around "$_" which made CGI.pm look for the parameter "'$_'", literally, which doesn't exist. Combine that with...
    3. 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://289957]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-26 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found