Back on course, our edit_three sub procedure.
if (%result) { &build_record_page(%result); }
Since %result
holds our freshly returned data, we look to see if it has a null value or not. If it has an actual value, we use that sub we saw at the start of the program, &build_record_page
, and send with it the hash %result
. This way, we now will have our values filled out for us in the form, instead of just empty values.
else { print qq~Error --- Record Does Not Exist ~; }
If %result
has a null value, we report the error.
print qq~
<CENTER>
<INPUT TYPE="submit" value="Edit Record"></CENTER>
<CENTER>
</FORM></TD></TR></TABLE></CENTER>~;
&footer;
Just closing up our form here, and printing the footer once again.
}
End of edit_three.
This is alot of work for just editing a freakin database entry, but here is our last step.
Since you guys already can guess the next sub is edit_four, I'll just go right to it.
sub edit_four {
$form{$db_key} = $form{'key'};
Here we set the $form{$db_key}
key in the hash to the value of $form{'key'}
. This is for the next procedure, which we sent the contents of %form
, and it will be processing $form{$db_key}
. Therefore, we can't send it an empty key when its very important now can we?
my ($line) = &make_data(%form);
The database line, which is now called $line
, will become the value of what &make_data
returns to it. Since this sub procedure was explained at the top of this tutorial, no need to cover it again,
my ($found) = 0;
my ($output) = "";
Both of these variables are set to my, and null values.
open (DATABASE, $file);
The database file is opened, once again, in read-only mode. Its handle is DATABASE.
while (<DATABASE>) {
You know what this means. It just loops as long as DATABASE has a value, so its not at the end of file.
chomp($_);
That newline is cut off of the record.
(/^\s*$/) and next;
Blank lines are skipped, and we just go to the next line.
my (%dat) = &process_record(&grab_data($_));
This you should recognize. %dat
has the results of &process_record
sent to it. &process_record
has sent to it the array created by &grab_data
, which is working on the current line ($_
).
if ($dat{$db_key} eq $form{'key'}) {
$output .= $line;
$found = 1;
}
If the current database entries key is equal to the key we just sent to it, then $output
has appended to it the value of $line
, which &make_data
just sent to us a few lines back. Since we already have the newline attached, we don't need to include another one. $found
is also now a non-null value, 1.
else {
$output .= "$_\n";
}
Otherwise, $output just has appended to the end of it the current record ($_
), plus a nice newline. }
close (DATABASE);
The read-only copy of DATABASE is now closed... as we need to open another copy.