Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Building data structures from CGI params

by fullermd (Priest)
on Aug 07, 2012 at 22:31 UTC ( #986096=note: print w/replies, xml ) Need Help??


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

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

What were you expecting?

Replies are listed 'Best First'.
Re^5: Building data structures from CGI params
by Anonymous Monk on Aug 08, 2012 at 03:26 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?

    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... :|

        I like that better than expecting a ->param, since that breaks it away from the contract of purely hash->hash.

        Adding a branch breaks no contracts

        sub build_cgi_struct { my ($iv, $errs, $conf) = @_; use Scalar::Util qw(blessed); my $blessed = blessed $iv; my $splitnull = 1; if( $blessed and UNIVERSAL::can( $iv, 'param') ){ $splitnull = 0; if( $iv->isa('CGI') ){ $iv = $iv->{"param"} ; # cheat :) } else { $iv = { map { $_ => [ $iv->param($_) ] } $iv->param }; } } ... ... if $splitnull;

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

        Well, OK, it's still just a few weeks. FSVO "few" :)

        I've uploaded a new version that does nullsplits by default (as well as one or two other minor tweaks).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986096]
help
Chatterbox?
[1nickt]: I am stumped, maybe someone brainy can clear my mind?
[1nickt]: This code does what I expect on the CLI: perl -wE 'sub x { 0 and 1 } say x()'
[1nickt]: (prints "0")
[Corion]: Hi 1nickt!
[1nickt]: When I put it in a file, I get the following: "Replacement list is longer than search list at 1290.pl line 4. syntax error at 1290.pl line 4, at EOF ...
[1nickt]: ... (Might be a runaway multi-line ;; string starting on line 3)"
[erix]: ( ha, the inmates of the retirement home have taken the kids to the cafe -- Good! :) )
[1nickt]: (there are three lines in the file)
[erix]: na namesti ( "At The German" ? )
[1nickt]: great goddess almighty, it's the subroutine name!

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2017-12-12 13:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (332 votes). Check out past polls.

    Notices?