nascent has asked for the wisdom of the Perl Monks concerning the following question:

I can build on this once I have the structure, but how do I use CGI to take ...say, two inputs via form on a page, have it output to a page, then allow a page where people can put them in some sort of order (ascii for simplicity).

An example would be "Give me your [name] and favorite [color]." Once done it would have a page showing the name and color, along with anyone else that filled out the form. Then there would be an option to sort by the person's name or the color.

I've checked the tutorial pages, no luck. I'd also just consult my Perl Black Book but I seem to have left that at home in favor of DNS & Bind. Wah. I apologize if this seems like I'm asking y'all to just do the work for me, that's not the case.

Merci,
nascent

Replies are listed 'Best First'.
Re: CGI
by chromatic (Archbishop) on Apr 01, 2000 at 10:49 UTC
    The trick is to add the inputs to a (persistent) data structure -- in this case, a List of Lists.
    # first, we get the parameters from the form with $q, a CGI.pm object my $name = $q->param('name'); my $color = $q->param('date'); # next, we add an anonymous array of these values to our array of all +users so far # remember the order: element 0 is name, element 1 is date push @all, [ $name, $date ]; # Not Included: # display that user's answers # start a form with a drop list asking which to sort by # in the next section of code, do something like this: # grab the parameter from the drop list my $sort_field = $q->param('sort_field'); # three-part comparison. Is the sort field 'name'? my $sort_sub = $sort_field eq 'name' ? # if yes, sort by the first field in the array of arrays sub { $a->[0] <=> $b->[0] } : # if no, sort by the second sub { $a->[1] <=> $b->[1] }; # remember, sort() can take a subroutine reference to change its behav +ior @all = sort $sort_sub @all; # Not Included: # display @all in the browser
    Not a big thing. :)
      Here is the <short> reference manual for cgi.pm (the perl module he was using) by the author: http://stein.cshl.org/WWW/software/CGI/cgi_docs.html Paul Rodrigues paul@plexi.com
      Hey chromatic... If you're reading this, would you mind remarking the heck out of that. It's sorta greek. I'm much more concerned with learning how it works than getting it to run, per se.

      Thanks,
      nascent

Poorly Worded
by nascent (Novice) on Apr 01, 2000 at 10:49 UTC
    I worded this so poorly. Let me rephrase.

    The first page asks...
    Your name
    Your favorite color

    After Tim fills out the first page, second page lists...
    John Blue
    Jen Tangerene
    Tim Green

    The third page allows them to list the page by ascii order by Name or Color.

    Maybe that is a clearer picture of what I'm looking for.

    "All paid jobs absorb and degrade the mind." --Aristotle

Re: CGI
by setantae (Scribe) on Apr 02, 2000 at 07:36 UTC
    You could do this the way chromatic suggested, with a persistent array.
    Another way to do it would be with the hidden input type.

    However, looking at what you're trying to do here, there's really no need for state maintenance.
    Therefore, all you'd need to do is to log all the input you get to a file (a flat text file would do if you're not expecting it to get big), or to a database (which can then do all the sorting for you).
    The flat text file approach would involve the use of something like:

    use CGI; open (DB, "data") || die "$!"; $cgi_object = new CGI(DB);
    and the database one will depend on DBI.pm and the relevant DBD module.
    Is the above what you are actually trying to do, or this an XYZ question?

    setantae@eidosnet.co.uk|setantae|www.setantae.uklinux.net