T
Testor
Hi all,
I posted this message in comp.lang.perl, but someone suggested I post
to this group instead. I wish I could delete the other one I hope
admins will note this.
Anyway, here goes:
I am writing a simple perl script to learn in the process. The script
is supposed to grab a receipt number from the query-string and write
it into a file.
To do that, here's what I did:
$query = new CGI;
$myreceipt = $query->param('bnkreceipt');
open(DATABASE, ">>bnkrecpts.db") or die "Can't write open file.
Reason: $!";
seek(DATABASE,0,2);
print DATABASE "$myreceipt\n";
close(DATABASE);
This works OK though not sure if it's the best way because I'm writing
duplicate receipt numbers. I tried to use an if statement to make sure
is the number exists in the file before writing it but I'm afraid I
wasn't successful I did something like:
open (THERECEIPT, "bnkrecpts.db") or die "Can't open file. Because:
$!";
flock(THERECEIPT,2);
$receiptnum = <THERECEIPT>;
close (THERECEIPT);
if ($receiptnum eq $myreceipt) {
stop and redirect or print something to the page etc..
}
As you can see since I'm still learning, my logic is out of no where
here
Comments on the above code will be appreciated.
I posted this message in comp.lang.perl, but someone suggested I post
to this group instead. I wish I could delete the other one I hope
admins will note this.
Anyway, here goes:
I am writing a simple perl script to learn in the process. The script
is supposed to grab a receipt number from the query-string and write
it into a file.
To do that, here's what I did:
$query = new CGI;
$myreceipt = $query->param('bnkreceipt');
open(DATABASE, ">>bnkrecpts.db") or die "Can't write open file.
Reason: $!";
seek(DATABASE,0,2);
print DATABASE "$myreceipt\n";
close(DATABASE);
This works OK though not sure if it's the best way because I'm writing
duplicate receipt numbers. I tried to use an if statement to make sure
is the number exists in the file before writing it but I'm afraid I
wasn't successful I did something like:
open (THERECEIPT, "bnkrecpts.db") or die "Can't open file. Because:
$!";
flock(THERECEIPT,2);
$receiptnum = <THERECEIPT>;
close (THERECEIPT);
if ($receiptnum eq $myreceipt) {
stop and redirect or print something to the page etc..
}
As you can see since I'm still learning, my logic is out of no where
here
Comments on the above code will be appreciated.