Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Populate CGI from HTTP::Request wo/ using %ENV ?

by Errto (Vicar)
on Mar 09, 2008 at 22:26 UTC ( #673140=note: print w/ replies, xml ) Need Help??


in reply to Populate CGI from HTTP::Request wo/ using %ENV ?

To the best of my knowledge neither CGI nor CGI::Simple give you a way to populate header information directly into their respective objects; they just pull it from ENV automatically. Those are the only two CGI-related modules I've personally worked with; there may be others. A quick experiment shows you can localize %ENV though:

#!perl -l sub foo { local %ENV; $ENV{foo} = '1'; print $ENV{foo}; } foo; print 'yes' if $ENV{foo} eq '1';
doesn't print "yes"


Comment on Re: Populate CGI from HTTP::Request wo/ using %ENV ?
Select or Download Code
Replies are listed 'Best First'.
Re^2: Populate CGI from HTTP::Request wo/ using %ENV ?
by ikegami (Pope) on Mar 09, 2008 at 22:33 UTC

    local %ENV doesn't remove the magic attached to %ENV, so changes to %ENV still affect every thread, so the race condition remains.

    THREAD 1 THREAD 2 ---------------------------------- ------------------------------ +---- { T local %ENV; i -> Process's R_M remains undef m $ENV{REQUEST_METHOD} = 'GET'; e -> Process's R_M becomes GET | | { | local %ENV; v -> Process's R_M becomes undef $ENV{REQUEST_METHOD} = 'PUT'; -> Process's R_M becomes PUT print($ENV{REQUEST_METHOD}); -> Prints process's R_M (PUT) } -> Process's R_M restored to undef print($ENV{REQUEST_METHOD}); -> Prints process's R_M (undef +) } -> Process's R_M restored to u +ndef

    That's why I suggested local *ENV instead. Then modifying %ENV doesn't change the processes environment.

    Update: Added illustration of two race conditions.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://673140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-07-29 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls