Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Entering data into MySql using CGI

by arturo (Vicar)
on Oct 09, 2001 at 01:17 UTC ( [id://117560]=note: print w/replies, xml ) Need Help??


in reply to Entering data into MySql using CGI

Can I have only one textarea (2columns 52rows) to accept all the states that she wishes to input and then parse that data?

OK, I wanted to just say "yes," because this really smells of homework (the restriction on the UI, for instance). But given that you *did* pose a specific question ...

CGI.pm isn't really the controlling factor. It depends on how the *user* enters it -- do they put line breaks or other spacers in themselves, or do they type it all in without spacers of any sort? So my advice is, in the HTML that presents the form with the text input field (be it an input field or a textarea), you tell the users what you want, and have your program proceed according to that. Visually easiest on you and on your users, I would think, is a comma or a space. Then, you just use split on the resulting string that you get using CGI.pm's param function. split is wicked-easy to use:

my $string="these are the times that try men's souls"; my @words = split /\s/, $string; # @words now holds "these", "are", "the" ... etc.

HTH

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'

Replies are listed 'Best First'.
Re: Re: Entering data into MySql using CGI
by ghost (Beadle) on Oct 09, 2001 at 01:37 UTC
    Since the state abbreviations are only two characters long, you can write a regex that should handle it with no problems.
    $states = "NY\nNJWA\nALCOOR"; print "-$1-\n" while($states =~ /(\w\w)/g);
    It seems an odd way to do it, though. Why would the user want to type in each state that way? Seems much, much easier to go with someone else's suggestion here and use a SELECT box instead.

    (And headlights would work at the speed of light, since they're traveling relative to your speed.)

      "And headlights would work at the speed of light.."

      Hmm, methinks you need to read up on physics a little bit.

      Or think about this. If you could* travel at the speed of light and you turned them on, are you saying the light would shine forwards and then reflect back to you? If so, then light is travelling faster than the speed of light. Oh but hang on, it can't, coz it travels at the speed of light. Therefore, you travel through where you want them to shine at the same speed that the light shines at, so the lights won't illuminate things in front of you, therefore they don't "work".

      cLive ;-)

      *...let's forget about the time travel and infinite mass problems etc here for simplicity's sake!

        I think you need to consider it a little more or, at the least, look into a textbook to confirm your suppositions. But I'm not going to go into it on this forum unless you write a Perl script that demonstrates your point.

        I was just making a slight (very slight) joke.

Log In?
Username:
Password:

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

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

    No recent polls found