Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Re: a question about working with the forms and array

by arturo (Vicar)
on Oct 15, 2003 at 00:28 UTC ( [id://299296]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: a question about working with the forms and array
in thread a question about working with the forms and array

Really, seriously, use CGI instead of your hand-rolled procedure. It's been battle-tested, and is amazingly convenient to use; it handles all the URL-encoding and so forth, and deals with (inter alia) URLS that read like /script.pl?foo=bar&baz=bletch, which would mess yours up. CGI will cut way down on the number of lines of code in your script, and make debugging easier. In fact, it's your hand-rolled procedure that appears to be the culprit. What you have in your HTML form, as generated by the script, is something like this:

<input type="checkbox" name="choice" value="foo.txt"> <input type="checkbox" name="choice" value="bar.txt">

And, assuming you check both boxes, there will be two name-value pairs in the input:
choice=foo.txt choice=bar.txt
and when your hand-rolled procedure runs, here's what happens: it encounters the first one, and sets $FORM{'choice'} to foo.txt; when it enounters the second one, it sets $FORM{'choice'} to bar.txt. So that's why you only see the last value.

Here's how you'd parse the form with CGI: at the top of your script, put use CGI qw(param); and to get the list of selected files, you'd simply add the one line @files = param('choice');. End of story.

I also want to lean hard on use strict. It may seem like it will make things more painful, but it will force you to think about which subroutines need access to which data. It will make your code so much more maintainable. And, as a final suggestion, I'd suggest you look into using CGI ;)

If not P, what? Q maybe?
"Sidney Morgenbesser"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found