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

how can i get value of input

#!/usr/bin/perl use CGI; $cgi = CGI->new; $query = $cgi->param("text"); print "my value is: $query\n"; print "Content-type: text/html\n\n"; <input name="text" value="hey">

Replies are listed 'Best First'.
Re: html input value
by davies (Monsignor) on Oct 09, 2018 at 10:22 UTC

    Have a look at Re: need some HTTP::Server::Simple::CGI example, especially the line my $who = $cgi->param('name');. I'm not clear about your precise problem, so I may be way off track when saying that you will need a server and a client for this and that the snippet you show seems to be trying to combine the two.

    Regards,

    John Davies

      i dont think my question is confusing. its simple and clear. how can you pass values from html its like how do u parse values from html source and read them in cgi script

        See CGI 101 which has simple examples. Your original code prints output before header which is no doubt going to cause you problems.

        Your question could be seen to require clarification because the example you posted will just manually print a header (since you use CGI you can use it to print the header for you) and display an text input with a predefined value. You have no <form> element, and no way of submitting the input to your script. You seem to be missing the very basics of how all this hangs together. https://developer.mozilla.org/en-US/docs/Web as well as the CGI documentation (note the clear warnings at the start), Tutorials -> Web Programming I know what I mean. Why don't you?.

Re: html input value
by LanX (Saint) on Oct 09, 2018 at 12:13 UTC
Re: html input value
by Anonymous Monk on Oct 09, 2018 at 13:53 UTC
    #!/usr/bin/perl use strict; use warnings; use CGI; my $cgi = CGI->new; my $query = $cgi->param("text"); print $cgi->header; print "my value is: $query\n" if $query; print qq(<form><input name="text" value="hey"></form>);
      Looks good to me. However, it will work only if OP meets the prerequisites
        Looks good to me. However, it will work only if OP meets the prerequisites …

        Bollocks! It works, period. This is not a college course or some job certification. Hackers learn by hacking, and that can be quite ugly, at first.