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

I've got a CGI flat file program that I'm working on. Here's my problem:
I've got a flat file database (| deliminated) that is in the following format:
stuff|morestuff|other|different|1
stuff|morestuff|other|different|3
stuff|morestuff|other|different|2
The last field is a sorting number. I need to make it so a user could arbitrarily choose which lines go where. I've set it up something like this:

For some reason this won't display forms, so here's the html

<FORM> <TABLE WIDTH="400"> <TR> <TD><INPUT TYPE="text" SIZE=3 value="3"></TD> <TD>Stuff</TD> <TD>More Stuff</TD> </TR> <TR> <TD><INPUT TYPE="text" SIZE=3 value="1"></TD> <TD>Stuff</TD> <TD>More Stuff</TD> </TR> <TR> <TD><INPUT TYPE="text" SIZE=3 value="2"></TD> <TD>Stuff</TD> <TD>More Stuff</TD> </TR> </TABLE> </FORM>

The user numbers the lines and I need the script to take those numbers, apply them to the proper part of the database, then sort the database based on those values. I've got the sort routine down if the numbers are already there, but I need to know how to set them with something like the above table so the user can change them. Does anyone have some ideas for doing this? Am I being clear enough? If not, please let me know and I'll try to clarify. Thanks!

Stamp_Guy
A bus station is where a bus stops... A train station is where a train stops... On my desk is a workstation...

Replies are listed 'Best First'.
Re: Flat File Sorting Issues
by mpolo (Chaplain) on May 07, 2001 at 10:19 UTC
    When you go into your decoding routine, you should have a set of names - values... You don't seem to have a NAME tag on the INPUT fields (maybe a transcription oversight). So, in the HTML, I'd have something like this (leaving out all the table stuff for clarity):
    <form action="myscript.cgi" method="post"> <input type="hidden" name="action" value="decode"> <input type="text" name="row1" value="3">List of values from row 1 <input type="text" name="row2" value="1">List of values from row 2 <etc...> <input type="submit" value="Chsnge order"> </form>

    Then in your CGI script, you just have to check for the presence of the "action" parameter. If it's there, you know to sort the lines based on the new values that were input by the user. (You indicated you knew how to do this, so I'll leave that explanation out...) Then write the file and voila!

    There are probably ways to make this more efficient, of course...

Re: Flat File Sorting Issues
by Chady (Priest) on May 07, 2001 at 10:18 UTC

    Yes you are not being clear enough, and if I understand this correctly, you don't have a problem

    fix this:

    • <FORM> should be <FORM action="somefile.pl">
    • your form should end with <input type="Submit">
    • get your somefile.pl to use CGI.pm
    • you get the values and use them..

    excuse me, I don't see the problem.


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
Re: Flat File Sorting Issues
by Beatnik (Parson) on May 07, 2001 at 11:14 UTC
    You could do something like:

    <TABLE> <TR> <FORM ACTION="tada.pl" METHOD="POST"> <TD>1</TD> <TD>Stuff</TD> <TD>More Stuff</TD> <TD><Input Type="Submit" Name="Action" Value="Up"> <Input Type="Submit" Name="Action" Value="Down"></TD> </TR></FORM> etc </TABLE>
    Unless you need text fields...

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: Flat File Sorting Issues
by Stamp_Guy (Monk) on May 07, 2001 at 16:43 UTC
    I'm sorry, I understand HTML and forms all, I just put stupid data in there so someone who wanted to could see it visually. My problem was how to take the entire array and apply the proper numbers to it. I think I've got it now though.