Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I've got a CGI script that I want to convert to PSGI. This is the result:
use CGI::Emulate::PSGI; use strict; use warnings; use CGI qw(:cgi-lib :standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $q = new CGI; my @keys = param(); my $state = ""; if(scalar @keys > 0){ $state = $keys[0]; } my $app = CGI::Emulate::PSGI->handler(sub { @keys = $q->param(); print $q->header; print "<center>"; print $q->h1('Some title'); print "</center>"; print $q->start_html(-title => 'Some title'); print $keys[0]; home(); sub home{ print "<center>"; print $q->h3('Pick an option.'); print $q->end_form; print "</center>"; print "<center>"; my $q0 = new CGI; print $q0->start_form( -name => 'some_button', -method => 'POST', -enctype => &CGI::URL_ENCODED, ); print $q0->submit( -name => 'click_me', -value => 'Do something', ); print $q0->end_form; print "</center>"; } print $q->end_form; });
After I click on 'Do something', I return to the same page (obviously), but it should print 'click_me'. This worked in CGI, but for some reason PSGI doesn't pass this variable. I can print other variables that are defined above. So my @keys = param(); doesn't seem to do a whole lot. Edit: Apparently PSGI uses %ENV, but I can't make it work with POST. It works with GET.

Edit: The solution is actually very easy. 'Your Mother' has the solution. I knew that you could compile your CGI scripts and emulate them. But if your run a perl server (like plackup), you get the next error: plackup: Variable "$variable" is not available at /location/of/script." The solution is to change the permissions of all global variables from 'my' to 'our'.

In reply to Passing variables in PSGI by TheChosenOne

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2023-05-27 23:07 GMT
Find Nodes?
    Voting Booth?

    No recent polls found