Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How do I read POST data that is not encoded, and was submitted without a parameter name

by sevensven (Pilgrim)
on Dec 15, 2001 at 00:20 UTC ( #132061=note: print w/replies, xml ) Need Help??


in reply to How do I read POST data that is not encoded, and was submitted without a parameter name

Great post Robin, thanks for the memory lane ;^)

Now, in my previous post to c-era previous question, I said that you could use CGI.pm (using the sample upload script that you where providing) and that was true, but only if the post data came encoded, wich it did since LWP::UserAgent plays nice with CGI and encodes the data.

CGI.pm cannot be used directly to solve your problem because it uses &; as CGI parameters separators and it will get confused by your XML sample file (as you can see if you send the CGI instance into Dumper)

The code in CGI.pm thats prevents its use is :

sub parse_params { my($self,$tosplit) = @_; my(@pairs) = split(/[&;]/,$tosplit); my($param,$value); foreach (@pairs) { ($param,$value) = split('=',$_,2); $value = '' unless defined $value; $param = unescape($param); $value = unescape($value); $self->add_parameter($param); push (@{$self->{$param}},$value); } }

Now, I do agree that CGI.pm gives you a nice framework with things like carping to browser, etc., and if I said previously that CGI.pm could be used, I'll make him behave :^)

You can create a new module, let us call it xmlCGI.pm, wich inherits from CGI.pm and redefines parse_params

xmlCGI.pm could be something like this :

package xmlCGI; use CGI; @ISA = ("CGI"); sub parse_params { my($self,$tosplit) = @_; #*** place all the input into a param named xml push (@{$self->{'xml'}}, $tosplit); #*** notice tosplit turned to empty #*** defusing the rest of this code $tosplit = ''; my(@pairs) = split(/[&;]/,$tosplit); my($param,$value); foreach (@pairs) { ($param,$value) = split('=',$_,2); $value = '' unless defined $value; $param = unescape($param); $value = unescape($value); $self->add_parameter($param); push (@{$self->{$param}},$value); } } 1;

Every cgi that uses xmlCGI.pm will receive a parameter named xml with all the post data.

Now, as with my previous post, I've got working code to back my claims ;^)

-- sevensven or nana korobi, ya oki
  • Comment on Re: How do I read POST data that is not encoded, and was submitted without a parameter name
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://132061]
help
Chatterbox?
[Cosmic37]: greetings earthlings please can someone improve my pathetic perl knowledge
[Cosmic37]: I have 2 files each with datetime and other data in unknown order and I want to find rows from both files matching by datetime and output them combined/ concatenated
[Corion]: Sure
[Corion]: Do you have any specific interests or general Perl knowledge?
[Cosmic37]: should I slurp? should I grep? Noble Lords I wish you good karma and beg your advice
[Corion]: Cosmic37: Ah, see perlfaq4, about How do I compute the intersection of two arrays
[Cosmic37]: I am out of practice; I use Perl for scientific programming for number crunching
[Corion]: Cosmic37: Basically, you read one file into a hash, keyed by your key, and then match the lines from the second file to that hash
[Cosmic37]: note that the two files only have datetimes which may match whereas other data per line is different format in file1 and file2 - is that really intersection?

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-06-29 16:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (672 votes). Check out past polls.