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

<form method="post" action="hello.pl"> <td>firstname</td> <td><input type="text" name="firstname"></td> </tr><tr> <td>lastname</td> <td><input type="text" name="lastname"></td> </tr><tr> <td><input type="submit"></td> </table> </form>
HELLO.PL
use CGI; use strict; $cgi = CGI->new(); my $fname = $cgi->param('firstname'); my $lname = $cgi->param('lastname'); print "Content-Type: text/html\n\n"; print <<HTML; <form method="post" action="welcome.pl"> <table width="100%"> <tbody><tr> <td><table cellpadding="5"> <tbody><tr> <td>Firstname</td> <td><b>$fname</b></td> </tr> <tr> <td>Lastname</td> <td><b>$lname</b></td> </tr> </form> HTML
WELCOME.PL
use CGI; use strict; $cgi = CGI->new(); my $x = $cgi->param('$fname'); my $q = $cgi->param('$lname'); print "Content-Type: text/html\n\n"; print <<HTML; <form method="get" action="welcome.pl"> <table width="100%"> <tbody><tr> <td><table cellpadding="5"> <tbody><tr> <td>Firstname</td> <td><b>$x</b></td> </tr> <tr> <td>Lastname</td> <td><b>$q</b></td> </tr> </form> HTML

Am getting the parameter very well from html file to HELLO.PL, bt am not getting parameter from HELLO.PL to WELCOME.PL, am trying to make it very clean and nice bt the problem is getting parameters from hello.pl to welcome.pl

Replies are listed 'Best First'.
Re: getting parameters
by fishmonger (Chaplain) on Nov 29, 2014 at 19:54 UTC

    Neither of those scripts will compile as written due to this line: $cgi = CGI->new(); which is missing the my keyword.

    hello.pl does not have any input fields or a submit button, so how do you expect it to send anything to welcome.pl?

      its like this i get the parameters from html file to hello.pl very well, no problem with these both files bt the problems comes when i want to pass the parameters(strings) i got in hello.pl to welcome.pl, thats why i did $x = $cgi->param('$fname') because we used $fname to show paramter from html in hello.pl, and now am trying to print $x to show the parameter or string value $fname from hello.pl take time look at the script flow, then u will understand wat am taking about, or try to run it at ur side

        You need to add inputs and a submit button in hello.pl

        # hello.pl use CGI; use strict; my $cgi = CGI->new(); my $fname = $cgi->param('firstname'); my $lname = $cgi->param('lastname'); print "Content-Type: text/html\n\n"; print $cgi->start_html; print <<HTML; <h3>Hello</h3> <table cellpadding="5"> <tr> <td>Firstname</td> <td><b>$fname</b></td> </tr> <tr> <td>Lastname</td> <td><b>$lname</b></td> </tr> </table> <form method="post" action="welcome.pl"> <input type="hidden" name="firstname" value="$fname"/> <input type="hidden" name="lastname" value="$lname"/> <input type="submit"/> </form> </body> </html> HTML

        and amend welcome.pl

        #!perl # welcome.pl use CGI; use strict; my $cgi = CGI->new(); my $x = $cgi->param('firstname'); my $q = $cgi->param('lastname'); print "Content-Type: text/html\n\n"; print $cgi->start_html; print <<HTML; <h3>Welcome</h3> <table cellpadding="5"> <tr> <td>Firstname</td> <td><b>$x</b></td> </tr> <tr> <td>Lastname</td> <td><b>$q</b></td> </tr> </table> </body> </html> HTML
        poj
Re: getting parameters
by ww (Archbishop) on Nov 29, 2014 at 20:06 UTC
    For starters,

    1. Tutorials
    2. Then Super Search.
    3. and, finally, opinion:
      You can solve the parameter passing easily, if you combine "hello.pl" and "welcome.pl" (lc is merely my preference)... rather than playing 'Ring around the rosie.' Why make it hard?

    ++$anecdote ne $data


      i dont understand u

      @ww

      u mean lc 'lowercase' hmm

      lc does different job

        In this case, when ww says 'lc', he's referring to the filenames of your Perl program files I think. eg: hello.pl as opposed to HELLO.PL.

        -stevieb

Re: getting parameters (life cycle of variables and programs and data persistence)
by Anonymous Monk on Nov 29, 2014 at 22:10 UTC

    See post and get problem especially Re^3: post and get problem

    $ perl -e " my( $foo, $bar ) = @ARGV; print qq{$foo and $bar\n}; " one + two one and two $ perl -e " print qq{$foo and $bar\n}; " and

    Its your basic life cycle of variables aka coping with scoping .... when the program ends, all the variables go away, there are no more variables, that is the life cycle of variables and programs

    If you want data to exist past the end of your program , if you want the data to persist, you have to save the data, to a file, to a database... CGI::Session offers a simple API for persisting data with a limited shelf life ...