Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I've had puzzlingly little luck finding this on my own, so I resort to the monastery...

I can't seem to find much existing code to build up data structures (rather than flat lists) from passed (GET/POST) CGI data. I know nobody wants to be seen holding up anything from That Other 'P' Web Language as an exemplar, but... well, there it is.

For a trivial example, going from an HTML form with data like:

<input type="text" name="foo{bar}" value="barval"> <input type="text" name="foo{baz}" value="bazval">

into something in perl like:

$foo = get_param('foo'); # $foo = { bar => 'barval', baz => 'bazval' }

CGI.pm and things roughly following its API provide ways (of greater or lesser convenience) of getting arrays of values. But finding something to build up hashes is an unrewarding search. The only thing I've managed to unearth is CGI::State, which is tightly tied to CGI.pm, is a little unsettling code- and known-limitation-wise, and has had 2 releases 3 days apart almost 10 years ago. Minor searching has turned up approximately 0 live uses of it. Doesn't encourage me to hitch my wagon to it...

Of course, I can just be the one that writes code to do it. I think highly enough of my ability for that. But I also think highly enough of Murphy that I'd rather not, and my Programmer's Laziness is in full-scale rebellion at the thought that this doesn't already exist. Surely I'm not actually just the second person in the last 15 years to want this?


In reply to Building data structures from CGI params by fullermd

Title:
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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found