in reply to Need Help With Writers Block
I'm storing all the warning points in the "@warningPoints" array with WPLong the first element and WPLat the seconds, this repeats itself through the array. Any suggestions on how to make this script take multiple warning points?
How about using a hash of hashes? It would fit better with your needs. You can use numbers as the keys, which will be considered strings by perl for that purpose anyway.
%warningPoints = ( 1 => { WPLong => 10, WPLat => 20, }, 2 => { WPLong => 30, WPLat => 40, }, ... );
To get multiple latitude and longitude values, you can create as many text fields as needed in your form, all named latitude or longitude, depending on what they expect for a value. The param() method will then return a list consisting of all the corresponding values. An example:
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use CGI; my $q = new CGI; print $q->header(), $q->start_html(); print $q->start_form(); print $q->textfield(-name => 'Latitude', -size => 10, -maxlength => 10 +, -override => 1); print $q->textfield(-name => 'Longitude', -size => 10, -maxlength => 1 +0, -override => 1); print $q->textfield(-name => 'Latitude', -size => 10, -maxlength => 10 +, -override => 1); print $q->textfield(-name => 'Longitude', -size => 10, -maxlength => 1 +0, -override => 1); print $q->submit(-name => 'choice', -value => 'Submit'); print $q->end_form(); my $choice = lc($q->param('choice')); if ($choice eq 'submit') { my @lat = $q->param('Latitude'); my @long = $q->param('Longitude'); print $q->pre(Dumper(\@lat)); print $q->pre(Dumper(\@long)); } print end_html();
The coordinates of the first point would then be ($long[0], $lat[0]), and so on for all points.
One good thing about this method is that you can add text fields with the help of some JavaScript, not having to submit the form each time. One bad thing is you have to use the -override switch to avoid the form, as well as the user, from being slightly confused in case you print it after submission.
|
|---|