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.


In reply to File::CounterFile problems : access from mulitple scripts and zeroing counter by hmbscully

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.