Hi, I'm more a less a newbie at perl ... here's my problem. I wrote a script that checks three separate files.
The first file it checks is a members database (flat file) to get the users members code. once it gets the members code (three digit number) it than refers to the other two flat files to get members data if it exists it displays information pertaining to that member only. If no data exists ... then it displays nothing ... sounds simple right ... thats what i thought. it was working fine, but now the two files of members data now contain information for employees and the members code field they have a alpha numeric code like "LD31" ... problem now is when script is checking members code and there is no data for that member it displays one of the employees information when it should display nothing.
Heres the Script:
$username = $ENV{REMOTE_USER};
print "Content-type: text/html\n\n";
&getuserinfo if ($ENV{'REQUEST_METHOD'} eq "GET");
sub getuserinfo {
open (DATA, "$membersdb") || warn "Members Area Error: Cannot open database file: $!";
@indata = <DATA>;
close (DATA);
foreach $entries (@indata) {
($name, $email, $user, $pass, $extra, $date) = split(/\|/, $entries);
if ($user eq $username) {
$found = 1;
last;
}
}
&getcurrserv if ($ENV{'REQUEST_METHOD'} eq "GET");
&getyearserv if ($ENV{'REQUEST_METHOD'} eq "GET");
exit;
}
sub getcurrserv {
open (DATA, "$cserv_file") || warn "Members Area Error: Cannot open Service file: $!";
@indata2 = <DATA>;
close (DATA);
foreach $entries2 (@indata2) {
($start2, $end2, $memcode2, $lname2, $fname2, $company2, $train2, $drill2, $standby2, $elected2, $meetings2, $misc2, $alarm2, $other2, $total2, $fireattend2, $firepercent2, $rescueattend2, $rescuepercent2) = split(/\|/, $entries2);
if ($memcode2 == $extra) {
print qq~
<tr><td><strong>This Year</strong></td> <td align=$tbactr>$end2</td> <td align=$tbactr>$total2</td> <td align=$tbactr>$standby2</td> <td align=$tbactr>$firepercent2</td> <td align=$tbactr>$rescuepercent2</td></tr>
~;
last;
}
}
}
sub getyearserv {
open (DATA, "$yserv_file") || warn "Members Area Error: Cannot open Service file: $!";
@indata3 = <DATA>;
close (DATA);
foreach $entries3 (@indata3) {
chop ($entries3);
($start3, $end3, $memcode3, $lname3, $fname3, $company3, $train3, $drill3, $standby3, $elected3, $meetings3, $misc3, $alarm3, $other3, $total3, $fireattend3, $firepercent3, $rescueattend3, $rescuepercent3) = split(/\|/, $entries3);
if ($memcode3 == $extra) {
print qq~
<tr><td><strong>Last Year</strong></td> <td align=$tbactr>$end3</td> <td align=$tbactr>$total3</td> <td align=$tbactr>$standby3</td> <td align=$tbactr>$firepercent3</td> <td align=$tbactr>$rescuepercent3</td></tr>
~;
last;
}
}
}
Here is an example of the members database:
Joey Buffon|email@email.com|userid|password|123|02/01/2005
Jane Doe|email2@email.com|userid|password|234|02/02/2005
John Doe|email3@email.com|userid|password|345|02/03/2005
Heres an example of data files (the two are the same with exception of the dates they are run):
01/01/2004|12/31/2004|123|Buffon|Joey|02|0|3|0|0|20|11
|0|0|34|13|1.28|10|0.95
01/01/2004|12/31/2004|234|Doe|Jane|02|0|3|0|0|21|11
|0|0|75|13|1.28|10|18.95
01/01/2004|12/31/2004|LD31|Schome|Jake|03|0|3|0|0|33|11
|0|1|75|15|1.28|10|21.95
Anybody have any idea why this is failing?
The first file it checks is a members database (flat file) to get the users members code. once it gets the members code (three digit number) it than refers to the other two flat files to get members data if it exists it displays information pertaining to that member only. If no data exists ... then it displays nothing ... sounds simple right ... thats what i thought. it was working fine, but now the two files of members data now contain information for employees and the members code field they have a alpha numeric code like "LD31" ... problem now is when script is checking members code and there is no data for that member it displays one of the employees information when it should display nothing.
Heres the Script:
$username = $ENV{REMOTE_USER};
print "Content-type: text/html\n\n";
&getuserinfo if ($ENV{'REQUEST_METHOD'} eq "GET");
sub getuserinfo {
open (DATA, "$membersdb") || warn "Members Area Error: Cannot open database file: $!";
@indata = <DATA>;
close (DATA);
foreach $entries (@indata) {
($name, $email, $user, $pass, $extra, $date) = split(/\|/, $entries);
if ($user eq $username) {
$found = 1;
last;
}
}
&getcurrserv if ($ENV{'REQUEST_METHOD'} eq "GET");
&getyearserv if ($ENV{'REQUEST_METHOD'} eq "GET");
exit;
}
sub getcurrserv {
open (DATA, "$cserv_file") || warn "Members Area Error: Cannot open Service file: $!";
@indata2 = <DATA>;
close (DATA);
foreach $entries2 (@indata2) {
($start2, $end2, $memcode2, $lname2, $fname2, $company2, $train2, $drill2, $standby2, $elected2, $meetings2, $misc2, $alarm2, $other2, $total2, $fireattend2, $firepercent2, $rescueattend2, $rescuepercent2) = split(/\|/, $entries2);
if ($memcode2 == $extra) {
print qq~
<tr><td><strong>This Year</strong></td> <td align=$tbactr>$end2</td> <td align=$tbactr>$total2</td> <td align=$tbactr>$standby2</td> <td align=$tbactr>$firepercent2</td> <td align=$tbactr>$rescuepercent2</td></tr>
~;
last;
}
}
}
sub getyearserv {
open (DATA, "$yserv_file") || warn "Members Area Error: Cannot open Service file: $!";
@indata3 = <DATA>;
close (DATA);
foreach $entries3 (@indata3) {
chop ($entries3);
($start3, $end3, $memcode3, $lname3, $fname3, $company3, $train3, $drill3, $standby3, $elected3, $meetings3, $misc3, $alarm3, $other3, $total3, $fireattend3, $firepercent3, $rescueattend3, $rescuepercent3) = split(/\|/, $entries3);
if ($memcode3 == $extra) {
print qq~
<tr><td><strong>Last Year</strong></td> <td align=$tbactr>$end3</td> <td align=$tbactr>$total3</td> <td align=$tbactr>$standby3</td> <td align=$tbactr>$firepercent3</td> <td align=$tbactr>$rescuepercent3</td></tr>
~;
last;
}
}
}
Here is an example of the members database:
Joey Buffon|email@email.com|userid|password|123|02/01/2005
Jane Doe|email2@email.com|userid|password|234|02/02/2005
John Doe|email3@email.com|userid|password|345|02/03/2005
Heres an example of data files (the two are the same with exception of the dates they are run):
01/01/2004|12/31/2004|123|Buffon|Joey|02|0|3|0|0|20|11
|0|0|34|13|1.28|10|0.95
01/01/2004|12/31/2004|234|Doe|Jane|02|0|3|0|0|21|11
|0|0|75|13|1.28|10|18.95
01/01/2004|12/31/2004|LD31|Schome|Jake|03|0|3|0|0|33|11
|0|1|75|15|1.28|10|21.95
Anybody have any idea why this is failing?