Gossamer Forum
Home : General : Perl Programming :

need simple sub_routine

Quote Reply
need simple sub_routine
I want to generate invoice numbers in sequence (for a shopping cart application)
I need a sub_routine to open a counter.txt file, grab the next number, update the counter.txt file and close the file. should also have file locking.
a pretty simple sub {for someone who knows perl that is} Any help would be appreciated.
Quote Reply
Re: need simple sub_routine In reply to
Code:

open (DB,">path_to_file") or exit;
$count = <DB>;
$invoicenumber = $count;
$count++;
flock(DB, 2) or die "Error: $!\n";
print DB $count;
close DB; # automatically removes file lock
return;
close(DB);
}

------------------