I'm writing a CGI script where a person will select their name, then enter a lat / long for a location, then multiple lat / longs for warning points. There will be anywhere from 1 to infinity warning points. Every time a warning point is added the script will refresh and show the added warning points plus a new space to enter in an additional warning point.

I pass the new warning points back to the CGI script as "WPLongX" and "WPLatX" where X is the data point number.

I'm having trouble thinking how I'm going to get the variable number of warning points that are passed back to my CGI script out and stored into an array.

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?
#!/usr/bin/perl -wT use CGI::Carp qw(fatalsToBrowser); use strict; use CGI; my $cgi = CGI->new(); # Create new CGI object. my $AuthorID; #Make $AuthorID global my $AuthorName; #Make $AuthorName global my $LocationLongitude; #Location longitude global my $LocationLatitude; #Location latitude global my $WarningLongitude; my $WarningLatitude; my @warningPoints; if ($cgi->param("LocationLongitude") && $cgi->param("LocationLatitude" +)) { # If Lat/Long present, add your warning points $LocationLongitude = $cgi->param("LocationLongitude"); $LocationLatitude = $cgi->param("LocationLatitude"); $AuthorID = $cgi->param("AuthorID"); $AuthorName = $cgi->param("AuthorName"); &print_warning_page; exit; } if ($cgi->param("AuthorID")) { #If author is passed back to the scrip +t, save the author info and goto the location page $AuthorID = $cgi->param("AuthorID"); &print_location_page; exit; } else {&print_author_page;} sub print_author_page { &print_header; print $cgi->start_form; print $cgi->popup_menu(-name=>'AuthorID', -values=>[qw/bob cecil/], -labels=>{'1'=>'bob', '2'=>'cecil'}, -default=>'bob'); print "<br>"; print $cgi->submit('Go'); print $cgi->end_form; } sub print_location_page { &print_header; print $cgi->start_form; print $cgi->hidden('AuthorID',"$AuthorID"); $LocationLatitude = $cgi->textfield(-name=>'LocationLatitude',-siz +e=>10,-maxlength=>10); $LocationLongitude = $cgi->textfield(-name=>'LocationLongitude',-s +ize=>10,-maxlength=>10); print <<EOF; <table border="0"> <tr> <td height="37">AuthorID:&nbsp</td> <td height="37">$AuthorID</td> <td height="37"></td> </tr> <tr> <td>Location Longitude:&nbsp</td> <td>$LocationLongitude</td> <td>( X Coord )</td> </tr> <tr> <td>Location Latitude:&nbsp;</td> <td>$LocationLatitude</td> <td>( Y Coord )</td> </tr> </table> EOF print "<br>"; print $cgi->submit('Go'); print $cgi->end_form; } sub print_warning_page { &print_header; print $cgi->start_form; print $cgi->hidden('AuthorID',"$AuthorID"); print $cgi->hidden("LocationLongitude","$LocationLatitude"); print $cgi->hidden("LocationLatitude","$LocationLatitude"); $WarningLatitude = $cgi->textfield(-name=>'Latitude',-size=>10,-ma +xlength=>10); $WarningLongitude = $cgi->textfield(-name=>'Longitude',-size=>10,- +maxlength=>10); print <<EOF; <table border="0"> <tr> <td height="37">AuthorID:&nbsp</td> <td height="37">$AuthorID</td> <td height="37"></td> </tr> <tr> <td>Location Longitude:&nbsp</td> <td>$LocationLongitude</td> <td>( X Coord )</td> </tr> <tr> <td>Location Latitude:&nbsp;</td> <td>$LocationLatitude</td> <td>( Y Coord )</td> </tr> EOF my $point = 1; foreach (@warningPoints) { my $WPLong = shift @warningPoints; my $WPLat = shift @warningPoints; print <<EOF; <tr> <td>Warning Longitude $point:&nbsp</td> <td>$WPLong</td> <td>( X Coord )</td> </tr> <tr> <td>Warning Latitude $point:&nbsp;</td> <td>$WPLat</td> <td>( Y Coord )</td> </tr> EOF print $cgi->hidden("WPLong$point","$WPLong"); print $cgi->hidden("WPLat$point","$WPLat"); $point++; } print <<EOF; <tr> <td>Warning Longitude:&nbsp</td> <td>$WarningLongitude</td> <td>( X Coord )</td> </tr> <tr> <td>Warning Latitude:&nbsp;</td> <td>$WarningLatitude</td> <td>( Y Coord )</td> </tr> </table> EOF print $cgi->checkbox(-name=>'checkbox_name', -checked=>1, -value=>'ON', -label=>'This is the last warning point.'); print "<br>"; print $cgi->submit('Go'); print $cgi->end_form; } sub print_header { print $cgi->header; }

In reply to Need Help With Writers Block by awohld

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.