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

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

by arturo (Vicar)
on Oct 15, 2003 at 00:28 UTC ( #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 /, 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://299296]
[LanX]: see soundfile https://en. wiki/human# Pronunciation
[Your Mother]: Just Another Perl 'Acker.
[LanX]: I pronounce it 'juːmən'
[Your Mother]: Hey, let's not bring antisemitism into the conversation.
[LanX]: for centuries posh English speakers tried to approach French, that's where all the trouble starts
[Eily]: Just another Perl coeurs
[Eily]: (perl with hearts, 'Acker with a French accent is pronunced like coeurs)
[LanX]: IMHO 'ju' for 'u' happens in English where they can't pronounce the French u (or German )
[LanX]: and I'm sure I read that *hotel* used to be pronounced 'otel by the English upperclass
[Your Mother]: American English vowels are pretty lazy/mumbly in general.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-03-27 17:13 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.