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

Hi:

Reluctant to come here for fear of being ruthlessly attacked. Just kidding. Very helpful.

my GetLink = 'one&reaction=two'; query string xxx.cgi?action=' + GetLink;

Want to recover the query params in:

my $query = new CGI; my $action = lc ($query->param('action')); ....... elsif ($action eq "one"){ my ($string1, $string1 ) = @_; my ($string2, $string2 ) = @_; warn("string2 = '$string2'");

or

elsif ($action eq "one"){ my $query = CGI->new(); my $string2 = $query->param('reaction'); warn("string2 = '$string2'");

Tried several other pieces of code. None work.

Replies are listed 'Best First'.
Re: .cgi?action params
by shmem (Chancellor) on May 28, 2017 at 13:22 UTC

    Please read I know what I mean. Why don't you?
    Then read Short, Self-Contained, Correct Example.

    That said, if you retrieve xxx.cgi?action=one&reaction=two, the following

    #!/usr/bin/perl use CGI; my $query = CGI->new; my $action = $query->param('action'); my $reaction = $query->param('reaction'); print $query->header, $query->start_html, "<h1>Result</h1>\n", "Action: ", $action || "no action", "<br>", "Reaction: ", $reaction || "no reaction", $query->end_html;

    will - if the webserver is correctly configured, if xxx.cgi has the correct permissions etc - serve a page reading:

    Result

    Action: one
    Reaction: two

    Now let me comment the snippets you posted.

    my GetLink = 'one&reaction=two'; query string xxx.cgi?action=' + GetLink;

    doesn't compile. Running that yields:

    No such class GetLink at - line 1, near "my GetLink" syntax error at - line 1, near "my GetLink =" Can't find string terminator "'" anywhere before EOF at - line 2.

    Then,

    my $query = new CGI; my $action = lc ($query->param('action')); ....... elsif ($action eq "one"){ my ($string1, $string1 ) = @_; my ($string2, $string2 ) = @_; warn("string2 = '$string2'");

    declaring a variable twice as in my ($string1,$string1) makes no sense at all. The special array @_ should only be used inside a subroutine and contains its arguments, if any. See perlvar and perlsub. Actually, don't see, read those pages.

    Lastly,

    elsif ($action eq "one"){ my $query = CGI->new(); my $string2 = $query->param('reaction'); warn("string2 = '$string2'");

    here you are masking the outer $query with a new CGI object inside the elsif block. Why?

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

      Hi. Thanks for input. All fixed now. As I seem to do, I do not post the actual code as it is part of a far larger operation which would just lead to confusion. This was screwed up. I did not copy and paste. I typed it anew with errors. You steered me in the correct direction . Again thanks. All turned out Ok.

        "As I seem to do, I do not post the actual code as it is part of a far larger operation which would just lead to confusion. This was screwed up. I did not copy and paste. I typed it anew with errors."

        Please don't do this, before posting run the code you claim to have a problem with, post the exact output as part of your problem. How do I post a question effectively?.

        Hello, tultalk. It's good to see you recognize that posting the whole hot mess of code was only going to add confusion. It's also good to see that you've realized that not posting actual code, data and results also confuses the issue.

        There is an additional hidden advantage to providing the oft-requested Short, Self-Contained, Correct Example:

        It forces you to restructure the problem. This often causes the mistake to reveal itself to you, as you suddenly toss out a handful of assumptions made whilst writing the original code.

        It's not only helpful in getting good answers from Perlmonks. It's also helpful in not needing to even ask for help.

Re: .cgi?action params
by Corion (Patriarch) on May 28, 2017 at 12:54 UTC

    In what sense did they not work?

    Note that you should only construct one CGI object per request.

    What is the value of $action?

    Why do you think that anything will end up in @_ in the code you show?

    Maybe you can show us the complete URL you are using to invoke your script and tell us in English words what you intend to happen?

    Then, also show us a short, 20 line CGI script you are using to make that happen, and please also tell us what happens instead.