my $roster_entry; my %roster_entries; while (!eof(ROSTER_FH)) { $roster_entry = CGI->new(\*ROSTER_FH); my $full_name = $roster_entry->param('last_name') . "," . $roster_entry->param('first_name'); $roster_entry->param('full_name', $full_name); $roster_entries{$full_name} = $roster_entry; } #### my $query = CGI->new(); if ($query->param('full_name')) { my $full_name = $query->param('full_name'); print p("
\$full_name = $full_name\n
"); print p("
\$roster_entries{$full_name}->param('address') = $roster_entries{$full_name}->param('address')\n
"); } else { # Display dropdown box with names print p("In order to update your contact information, select your name below and click the Submit button\n"); print start_form; print p($query->popup_menu( -name=>'full_name', -values=>[sort keys %roster_entries] )); print p(submit("Submit")); print end_form, end_html; } ##
## $full_name = Last1, First1 $roster_entries{Last1, First1}->param('address') = ->param('address') #### $full_name = Last1, First1 $roster_entries{Last1, First1}->param('address') = 111 First Street #### #!c:/perl/bin/perl.exe use strict; use warnings; use CGI qw(:standard); use Fcntl qw(:flock); my $ROSTER_CGI_FILE = "c:/temp/test_roster.txt"; print header, start_html(), h2(); # This is for the page that displays in the browser #### Getting existing roster data open(ROSTER_FH, "+< $ROSTER_CGI_FILE") or bail("Cannot open $ROSTER_CGI_FILE: $!"); flock(ROSTER_FH, LOCK_EX) or bail("Cannot flock $ROSTER_CGI_FILE: $!"); my $roster_entry; my %roster_entries; # Creating an array of roster objects from existing list while (!eof(ROSTER_FH)) { $roster_entry = CGI->new(\*ROSTER_FH); my $full_name = $roster_entry->param('last_name') . ", " . $roster_entry->param('first_name'); $roster_entry->param('full_name', $full_name); $roster_entries{$full_name} = $roster_entry; } ### Starting the update process my $query = CGI->new(); if ($query->param('full_name')) { # If user has chosen a name from the dropdown box, then provide additional dropdown boxes already filled in with current information my $full_name = $query->param('full_name'); print p("
\$full_name = $full_name\n
"); print p("
\$roster_entries{$full_name}->param('address') = $roster_entries{$full_name}->param('address')\n
"); print p("Updating entry for: ", $full_name, "\n
"); print start_form; print p("Street Address: ", $query->textfield(-NAME => "address", -VALUE => "$roster_entries{$full_name}->param('address')", -SIZE => 50, -maxlength=>50)); print("City: ", $query->textfield(-NAME => "city", -VALUE => "$roster_entries{$full_name}->param('city')", -SIZE => 20, -maxlength=>20)); print("  State: ", $query->textfield(-NAME => "state", -VALUE => "$roster_entries{$full_name}->param('state')", -SIZE => 2, -maxlength=>2)); print("  Zip: ", $query->textfield(-NAME => "zip", -VALUE => "$roster_entries{$full_name}->param('zip')", -SIZE => 7, -maxlength=>7)); print p("Home phone: ", $query->textfield(-NAME => "home_phone", -VALUE => "$roster_entries{$full_name}->param('home_phone')", -SIZE => 12, -maxlength=>12)); print p("Cell phone: ", $query->textfield(-NAME => "cell_phone", -VALUE => "$roster_entries{$full_name}->param('cell_phone')", -SIZE => 12, -maxlength=>12)); print p("Email: ", $query->textfield(-NAME => "email", -VALUE => "$roster_entries{$full_name}->param('email')", -SIZE => 30, -maxlength=>30)); print p(submit("send"), defaults("clear")); print end_form, end_html; } else { # Display dropdown box with names print p("In order to update your contact information, select your name below and click the Submit button\n"); print start_form; print p($query->popup_menu( -name=>'full_name', -values=>[sort keys %roster_entries] )); print p(submit("Submit")); print end_form, end_html; } close(ROSTER_FH); ################################################## # # Subroutines # ################################################## sub bail { my $error = "@_"; print h1("Unexpected error"), p($error), end_html; die $error; }