Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found