http://qs321.pair.com?node_id=495149

hmbscully has asked for the wisdom of the Perl Monks concerning the following question:

Dearest Monks,

I have the following code in a larger script which writes a form submission to a flatfile, called each time the form is submitted:

#increment file for count my $asrnumber = File::CounterFile->new("./asr_counter.txt"); $asrnumber->lock(); $asrnumber->inc; $asrnumber->unlock();

I then have another script that will take the flatfile, check the counter for number of submissions, and email the file to some waiting party:

#!/usr/bin/perl # asr_archive.pl # script to email and archive ASR submissions for backup use warnings; use CGI qw/:standard/; use CGI::Carp 'fatalsToBrowser'; use MIME::Lite; use POSIX; use File::CounterFile; require '../code_paths.conf'; $from_email = "webmaster\@xyz.org"; $to_email = "wendy\@xyz.org"; $orig_file = "asr_submissions.txt"; $file_date = POSIX::strftime("%d%m%Y_%H%M", localtime); $new_file = "asr_submissions_$file_date.txt"; system "mv $orig_file $new_file"; #rename the flatfile with date system "mv $asr_data/$new_file $asr_backup"; #move flatfile to backup +directory my $count = File::CounterFile->new("./asr_counter.txt"); $count->lock(); $count->value; $count->unlock(); &Email_Results; #email flatfile sub Email_Results{ $msg = MIME::Lite->new(From => $from_email, To => $to_email, Subject => "$count ASR submissions - $file_date +", Type => 'multipart/mixed'); $msg->attach(Type => 'application/octet-stream', Path => "$asr_backup/$new_file", Filename => $new_file ); $msg->send(); }

The problem I am running into is that if I let the File::CounterFile module create the counter file on its own, it ends up with a different owner than the script (or that I have access to) and I cannot access it from this script. I copied the module-created file and renamed it to the file I am now calling, which seems to work.

The problem is I need to zero out the counter each time the above script is run and I can't quite figure out how to do that other than to just delete the file... and when the original script would recreate the file it would have the bad permissions again...

Hoping there is both a quick and dirty and quick and neat solution to this... thanks.