JonnyRed77
Programmer
Hi there. I'm trying to read info from a text file & store it in an array. Each bit of info is seperated by a ",". I tried using the split function to seperate them but will not work. When I go to print out the array, it just prints out my file location as a string rather than printing the file info. Writing to the file is fine, just can't read from it. Any help would be great.
John
-------------------------------------------------
Come visit my website
------------------------------------
John
-------------------------------------------------
Code:
#!c:/perl/bin/perl
use CGI ':standard';
if (!param()){
create_form();
}
else {
process_form();
}
sub create_form {
print header, start_html( {-title=>'Beta Testers Registration Form', -bgcolor=>'#ffffff'} );
print start_form( {-action=>'BetaTesters.cgi'} );
print "
<table width=\"280\" height=\"200\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr>
<td width=\"130\">Surname</td>
<td><input type=\"text\" name=\"Surname\"></td>
</tr>
<tr>
<td width=\"130\">Forename</td>
<td><input type=\"text\" name=\"Forename\"></td>
</tr>
<tr>
<td width=\"130\">Extension Number</td>
<td><input type=\"text\" name=\"ExNumber\"></td>
</tr>
<tr>
<td width=\"130\">E-mail Address</td>
<td><input type=\"text\" name=\"Email\"></td>
</tr>
<tr>
<td width=\"130\">Department</td>
<td><select name=\"Department\">
<option>--- Choose One ---
<option>Finance
<option>Sales
<option>Operations
<option>Personnel
<option>Design
</select>
</td>
</tr>
<tr>
<td colspan=\"2\"> </td>
</tr>
<tr>
<td colspan=\"2\"><input type=\"submit\" value=\"Submit Details\">
<input type=\"reset\" value=\"Clear Form\"></td>
</tr>
</table>";
print end_form;
print end_html;
}
sub process_form {
$surname = param('Surname');
$forename = param('Forename');
$exnumber = param('ExNumber');
$email = param('Email');
$department = param('Department');
$FullName = "$surname" . "_" . "$forename";
$TesterFile = "c:/progra~1/apache~1/apache/bin/list.txt";
if ($email !~ m/@/) {
print "You entered an invalid e-mail address.";
}
else {
open(LIST, ">>$TesterFile") || die "Can't open file: $!";
print LIST "$FullName,$exnumber,$email,$department\n";
close LIST;
open(LIST, "<$TesterFile") || die "Can't read file: $!";
# PROBLEM IS HERE
@FileContents = split(/,/, $TesterFile);
print header, start_html( {-title=>'Beta Testers Application Results'} );
print "$FileContents[0]";
close LIST;
print end_html;
}
}
Come visit my website
------------------------------------