Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Building data structures from CGI params

by Anonymous Monk
on Jul 27, 2012 at 09:36 UTC ( #984008=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Building data structures from CGI params
in thread Building data structures from CGI params

You forgot how CGI::Vars works, https://metacpan.org/module/CGI::Struct#Auto-arrays doesn't account for it

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use CGI; use CGI::Struct; my $q = CGI->new('row[]=row;row[]=row;row[]=row;row[]=your boat'); my %qVars = $q->Vars; my @errors; my $struct = build_cgi_struct \%qVars, \@errors; dd $q, \%qVars, $struct, \@errors; ### WORKAROUND for stupid Vars (must've written this line 100 times) %qVars = map { $_ => [ $q->param($_) ] } $q->param; dd \%qVars; $struct = build_cgi_struct \%qVars, \@errors; dd $struct, \@errors; __END__ ( bless({ ".charset" => "ISO-8859-1", ".fieldnames" => {}, ".iterator" => 2, ".parameters" => ["row[]"], "escape" => 1, "param" => { "row[]" => ["row", "row", "row", "your boat"] +}, "use_tempfile" => 1, }, "CGI"), { "row[]" => "row\0row\0row\0your boat" }, { row => ["row\0row\0row\0your boat"] }, [], ) { "row[]" => ["row", "row", "row", "your boat"] } ({ row => ["row", "row", "row", "your boat"] }, [])


Comment on Re^3: Building data structures from CGI params
Download Code
Re^4: Building data structures from CGI params
by fullermd (Curate) on Aug 07, 2012 at 22:31 UTC

    I'm not sure what you mean. { row => ["row", "row", "row", "your boat"] } looks like the "right" answer to me...

    What were you expecting?

      I'm not sure what you mean.  { row => ["row", "row", "row", "your boat"]  }   looks like the "right" answer to me... What were you expecting?

      That line is generated by the workaround

      This is Vars output

      { "row[]" => "row\0row\0row\0your boat" },

      And this is what your module does with vars output

      { row => ["row\0row\0row\0your boat"] },

      This is the bug, it forgot to split on \0, because Vars joins on \0

      or better still it should simply accept a CGI.pm compatible object (one with param method, whether its CGI/CGI::Simple/CGI::Lite.....) and use the Vars workaround on it

      Do you get it now?

        That line is generated by the workaround

        [...]

        This is the bug, it forgot to split on \0, because Vars joins on \0

        Oh, I see what you mean. Hm. I hate that NUL stuff...

        I guess the best thing would be to add a config'able (probably on by default) splitting on them to the processing. I like that better than expecting a ->param, since that breaks it away from the contract of purely hash->hash.

        I'll see if I can't get that into a new release in the next few weeks. Annoyingly busy... :|

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-08-21 10:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (134 votes), past polls