Please check code & logic

T

Testor

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) {
print something or whatever here...

}

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.
 
J

Joe Smith

Testor said:
I guess no one wants to comment on this.

1) You posted to comp.lang.perl instead of comp.lang.perl.misc; that's
where the action is.
2) A database that can hold only one number at a time is rather boring.
It's better to use a real database with professional-grade record locking.

-Joe
 
T

Testor

Joe Smith said:
1) You posted to comp.lang.perl instead of comp.lang.perl.misc; that's
where the action is.
2) A database that can hold only one number at a time is rather boring.
It's better to use a real database with professional-grade record locking.

-Joe

Joe,

Thanks for the reply. I shall try to post to .misc as suggested. A
database for holding one number is boring as you said, but I find it
good for training since I'm not doing much just to get the idea.

Once again, thanks for your reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top