$job = "$FORM{'job'}";
sub check_no {
open(DB, "/home/check.db") || die "Unable to open. Reason: $!";
foreach $line (<DB>) {
chomp;
if ($line =~ /$job/) {
&error(job_already_exists);
}
else {
&check_job
}
}
}
#########################################
sub check_job {
$exists = 0;
open(TXT, "/home/check.db") || die "Unable to open. Reason: $!";
foreach $line (<TXT>) {
chomp;
if ($line =~ /$job/) { $exists = 1; last;}
}
close(TXT);
if (!$exists) {
open(TXT, ">>/home/check.db") || die "Cant open file. Reason: $!";
print TXT "$job\n" ;
close (TXT) ;
}
}
###################################
If I enter the job #: 000789, it accepts it without any error and write it to the check.db and the next time if someone tries to add the same job no i.e 000789 to DB it will give an error(job_already_exists). Its fine till here its according to script
Now the problem is: its also giving error on:
00078
0007
000
00
0
Its giving an error to all above job no. &error(job_already_exists). Even I didn't enter any of the above job nos. except for 000789. Where I m wrong please help?
sub check_no {
open(DB, "/home/check.db") || die "Unable to open. Reason: $!";
foreach $line (<DB>) {
chomp;
if ($line =~ /$job/) {
&error(job_already_exists);
}
else {
&check_job
}
}
}
#########################################
sub check_job {
$exists = 0;
open(TXT, "/home/check.db") || die "Unable to open. Reason: $!";
foreach $line (<TXT>) {
chomp;
if ($line =~ /$job/) { $exists = 1; last;}
}
close(TXT);
if (!$exists) {
open(TXT, ">>/home/check.db") || die "Cant open file. Reason: $!";
print TXT "$job\n" ;
close (TXT) ;
}
}
###################################
If I enter the job #: 000789, it accepts it without any error and write it to the check.db and the next time if someone tries to add the same job no i.e 000789 to DB it will give an error(job_already_exists). Its fine till here its according to script
Now the problem is: its also giving error on:
00078
0007
000
00
0
Its giving an error to all above job no. &error(job_already_exists). Even I didn't enter any of the above job nos. except for 000789. Where I m wrong please help?