f



Getting values from a CGI call

I am writing a cgi script, and I want to get at the values which were
passed to it as arguments.  I finally found a way to do this, at
http://www.perldoc.com/perl5.8.0/lib/CGI.html.  You say
    use CGI qw/:standard/;
    my $edges = param('foo');
and it works.

But before I found this web page, I tried "Learning Perl", which
recommends (page 187)
    use CGI qw(:standard);
    my $edges  = param{"foo"};
This does not work.  Instead it sets $edges to "".

Then I tried "Perl in a Nutshell", which recommends (page 330)
    use CGI;
    my $edges = $query->param("foo");
This is worse.  My script stops at the second of the above lines.

Now I can't believe that these books are actually wrong about something
so basic.  Yet what they recommend does not work on my system.  Can
anyone explain what is going on here?

Nick
-- 
Nick Wedd    nick@maproom.co.uk
0
nick927 (55)
10/15/2003 2:53:12 PM
comp.lang.perl.misc 33233 articles. 2 followers. brian (1246) is leader. Post Follow

5 Replies
15952 Views

Similar Articles

[PageSpeed] 25

[posted & mailed]

On Wed, 15 Oct 2003, Nick Wedd wrote:

>But before I found this web page, I tried "Learning Perl", which
>recommends (page 187)
>    use CGI qw(:standard);
>    my $edges  = param{"foo"};
>This does not work.  Instead it sets $edges to "".

I doubt "Learning Perl" recommends using param {...}.  Those {}'s should
be ()'s, and if the book has {}'s, then it's a typo.

>Then I tried "Perl in a Nutshell", which recommends (page 330)
>    use CGI;
>    my $edges = $query->param("foo");
>This is worse.  My script stops at the second of the above lines.

Because you never created $query as a CGI object.

  use CGI;
  my $query = CGI->new;
  my $edges = $query->param('foo');

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

0
Jeff
10/15/2003 3:02:43 PM
In message 
<Pine.SGI.3.96.1031015110023.39267A-100000@vcmr-64.server.rpi.edu>, Jeff 
'japhy' Pinyan <pinyaj@rpi.edu> writes

>>But before I found this web page, I tried "Learning Perl", which
>>recommends (page 187)
>>    use CGI qw(:standard);
>>    my $edges  = param{"foo"};
>>This does not work.  Instead it sets $edges to "".
>
>I doubt "Learning Perl" recommends using param {...}.  Those {}'s should
>be ()'s, and if the book has {}'s, then it's a typo.
>
>>Then I tried "Perl in a Nutshell", which recommends (page 330)
>>    use CGI;
>>    my $edges = $query->param("foo");
>>This is worse.  My script stops at the second of the above lines.
>
>Because you never created $query as a CGI object.
>
>  use CGI;
>  my $query = CGI->new;
>  my $edges = $query->param('foo');

Thank you, thank you.  I must learn to read more carefully.

Nick
-- 
Nick Wedd    nick@maproom.co.uk
0
Nick
10/15/2003 3:19:32 PM
Nick Wedd wrote:
 
(snipped)

> But before I found this web page, I tried "Learning Perl", which
> recommends (page 187)

>     use CGI qw(:standard);
>     my $edges  = param{"foo"};
> This does not work.  Instead it sets $edges to "".


use CGI qw(:standard);
$edges  = param("foo");

print $edges;


PRINTED RESULTS:
________________

C:\APACHE\USERS\TEST>perl test.pl foo=test
test


 
> Then I tried "Perl in a Nutshell", which recommends (page 330)
>     use CGI;
>     my $edges = $query->param("foo");
> This is worse.  My script stops at the second of the above lines.


use CGI;
$query = CGI::new();

$edges = $query->param("foo");

print $edges;


PRINTED RESULTS:
________________

C:\APACHE\USERS\TEST>perl test.pl foo=test
test



Purl Gurl
-- 
Corvette Mako Sharks! 56 Chevy Napco 4X4!
http://www.purlgurl.net/~godzilla/
0
Purl
10/15/2003 3:32:06 PM
On Wed, 15 Oct 2003, Purl Gurl wrote:

>use CGI;
>$query = CGI::new();

I would advise against doing that.  While the CGI.pm module goes to great
pains to make sure slip-ups like that don't wreck the program, most
object-oriented modules don't make that allowance.  The primary difference
between CGI::new() and CGI->new() is that CGI::new() sends NO arguments to
the new() function in the CGI:: namespace, whereas CGI->new() sends the
argument 'CGI' to the method 'new' in CGI's hierarchy (which is CGI::new
in this case).

That is:

  package Foo;
  sub bar {
    my $class = shift;
    my @other = @_;
    print "Blessing into '$class'\n";
    print "Other data: (@other)\n";
    bless \@other, $class;
  }

If this were to be used thus:

  my $obj = Foo->bar(1, 4, 9);

we'd get

  Blessing into 'Foo'
  Other data: (1 4 9)

However, if we made the mistake of using Foo::bar(1, 4, 9), we'd get

  Blessing into '1'
  Other data: (4 9)

So what it comes down to is this:  it's important not to mistake a class
method call (Foo->bar) with a package function call (Foo::bar).

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

0
Jeff
10/15/2003 4:22:00 PM
Jeff Pinyan wrote:
 
> Purl Gurl wrote:

(snipped)
 
> > use CGI;
> > $query = CGI::new();
 
> I would advise against doing that.

I have sense enough to never use Stein's module.

You need to speak with Ellen Siever, Stephen Spainhour,
Nathan Patwardhan, on this specific topic.

The originating author misquoted both "Learning Perl" and
"Perl In A Nutshell" example syntax. I corrected his quotes
by directly quoting the original authors.

Another variation you will read on this is,

$query = new CGI;


Purl Gurl
-- 
Roberta The Remarkable Robot
 http://www.purlgurl.net/~callgirl/roberta/roberta.cgi
Roberta's Operator's Manual
 http://www.purlgurl.net/~callgirl/roberta/help.html
0
Purl
10/15/2003 4:46:00 PM
Reply:

Similar Artilces:

what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server?
Hi all, I have small doubt, the following code works fine in Apache server. But not completely in Tomcat. Why?? ------------------------ #!C:\Perl\bin\perl.exe # hello.pl use CGI; $cgi = new CGI; print $cgi->header; printf "Hello world"; system("perl Hi.pl"); ------------------------ #!C:\Perl\bin\perl.exe # hi.pl print "Hi"; ------------------------ When I tried in Tomcat, the script prints only Hello world Why? What's wrong? kath. kath wrote: > I have small doubt, the following code works fine in Apache server. > But not completely in Tom...

why does it not get the value in perl run shell script to call include php file?
two file in the same folder fun.php 775 1.pl #! /usr/bin/perl $i = 0; $decryptCC = `echo '<?php include( "/home/webserve.ca/eselect/ eselect_test/fun.php" ); echo "CC" . dcc( "$i", "" ) . "CC"; ?>' | php -q`; print $decryptCC; 2. fun.php <? function dcc($char) { return "test"; } ?> 3. 1.sh #!/usr/bin/php -q <?php include('fun.php'); echo dcc(1); ?> run ./1.sh get test. 2. run ....

Apache Perl CGI calls another Perl script on another network server
Using Apache on Win32, my Perl cgi scripts run fine. However, I have one perl cgi script, that makes a system call to fire off another perl script. This works fine as long as the second script is in the same folder as the original cgi. But now I want to store the called script on another server in our network. When I do that, the cgi script will not fire the script (I'm using the full path to call the second script). It works for a command line perl program running on the web server, so I know the servers are talking to each other, but not from a cgi script. I don't want to run cgi ...

Apache Perl CGI calls another Perl script on another network server
Using Apache on Win32, my Perl cgi scripts run fine. However, I have one perl cgi script, that makes a system call to fire off another perl script. This works fine as long as the second script is in the same folder as the original cgi. But now I want to store the called script on another server in our network. When I do that, the cgi script will not fire the script (I'm using the full path to call the second script). It works for a command line perl program running on the web server, so I know the servers are talking to each other, but not from a cgi script. I don't want to run cgi ...

windows program return values vs perl return values from a call to system() -- windows post only
I sent this to a friend to demonstrate the way to manage the return values from a call to system() out of a perl script. Hopefully I did it ok. (Post regards windows - activestate perl only.) ------------------------------------------------------------------ use strict; #disable iff too restrictive where iff = 'if and only if' use warnings; #disable iff too noisy where iff = 'if and only if' my $prog_to_B_run="C:\\WINNT\\system32\\notepad.exe"; system("$prog_to_B_run"); my $stat=$?; if ($stat) { print "The exit code of the program was $stat\n&quo...

C++ calling perl script
I have the below sample program which pushes the arguments to Perl stack an= d then calls "eval_sv". The sample perl statements get executed but i'm not= able to retrieve the variables passed from C++ as Perl arguments. Please l= et me know what i am missing in the below program Output of the program Hello World Test 100Testing complete This line doesn't print the value of $a and $b string three =3D "print 'Test\n'; my $z =3D 100; print $a; print $b; print = $z;"; Here is my code: #include <EXTERN.h> #inclu...

VALUES and CALL-WITH-VALUES
I want to know why VALUES and CALL-WITH-VALUES are necessary in Scheme. They seem to have no meaning independently. Aren't the following simple macros are sufficient? From a practical point of view such as variable bindings, the latter macros are rather better than the former procedures. (define-syntax mu (syntax-rules () ((mu argument ...) (lambda (m) (m argument ...))))) (define-syntax nu (syntax-rules () ((nu argument arguments ...) (lambda (n) (apply n argument arguments ...))))) ((mu 1 2 3) +) => 6 (call-with-values (lambda () (values 1 2 3)) +) => 6...

deisng perl perl programmibng langs in perl
then liberate big war zones with notes on their download pages. -r www.thevoid1.net/ ...

Web resources about - Getting values from a CGI call - comp.lang.perl.misc

National Review Sheds Subscribers Over ‘Don’t Vote Donald Trump’ Editorial
Chants of “Don’t vote Donald Trump” have resounded from both sides of political aisle since his entry into the race, and now National Review, ...

Stranded Motorist Kills Man Trying to Help Him, Sheriff Says
New York Times Stranded Motorist Kills Man Trying to Help Him, Sheriff Says New York Times The authorities in North Carolina accused a motorist ...

Police charge 17-year-old in Canada after 4 shot dead
Police on Saturday charged a 17-year-old boy with four counts of first-degree murder and seven counts of attempted murder in a mass shooting ...

Duquesne Basketball Team, Stuck on Turnpike, Plays Cards and Makes a Snow Angel
ABC News Duquesne Basketball Team, Stuck on Turnpike, Plays Cards and Makes a Snow Angel New York Times When the team bus lurched to a halt ...

Blue Origin Executes First Successful Relaunch And Landing Of Reusable Rocket
The private sector space race is heating up, and Amazon.com co-founder Jeff Bezos’ Blue Origin is back out in front with the first successful ...

Kerry confident Syria talks can proceed
Reuters Kerry confident Syria talks can proceed Reuters RIYADH U.S. Secretary of State John Kerry said on Saturday he was confident Syria ...

Jurors will start deliberation Thursday in the sex crimes trial for a fired Oklahoma City police officer ...
The jury deliberated into the night Wednesday for the third time in the sex crimes trial of fired Oklahoma City police officer Daniel Ken Holtzclaw. ...

John Legend & ‘Underground’ EP On “Slow Moving Change” Of Oscars & Diversity – Sundance
"I think what the Academy did this week is a step in the right direction but it's going to be a slow moving change because the Academy reflects ...

Stunning Star Wars visual effects breakdown shows how Maz Kanata was brought to life
Much was made of The Force Awakens' return to practical effects after the overly-sanitized look of the prequel trilogy, but make no mistake: ...

Kerry to press China over North Korea, urge ASEAN unity over South China Sea
By David Brunnstrom RIYADH (Reuters) - U.S. Secretary of State John Kerry begins a visit to East Asia on Sunday in which he plans to press China ...

Resources last updated: 1/24/2016 3:32:53 AM