Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)

by djp (Hermit)
on Dec 03, 2009 at 23:05 UTC ( [id://810975]=note: print w/replies, xml ) Need Help??


in reply to Re: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
in thread RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)

++merlyn. I followed the highlander link and spotted this in the code listing at line 4:
open HIGHLANDER, ">>/tmp/renew.cgi.highlander" or die "Cannot open hig +hlander: $!";
I never (ever!) thought I would have cause to correct merlyn, but this contains one of my pet peeves, error messages which don't tell you what's happening, e.g.
Cannot open highlander: No disk space at ... Cannot open highlander: Permission denied at ...
Analyzing any problem requires the support person to read the code to discover the problem filename. They don't want to do that (and in a compiled language they can't), they just want to fix the problem. Suggest this:
my $highlander = '/tmp/renew.cgi.highlander'; open HIGHLANDER, ">>$highlander" or die "Cannot open $highlander: $!";
Cannot open /tmp/renew.cgi.highlander: No disk space at ... Cannot open /tmp/renew.cgi.highlander: Permission denied at ...
  • Comment on Re^2: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
by Arunbear (Prior) on Dec 05, 2009 at 21:47 UTC
    autodie both adds the file name to the error message and saves you from having to do the or die ...; dance:
    # open.pl use strict; use warnings; use autodie; open HIGHLANDER, ">>/root/renew.cgi.highlander";
    when run (as non a root user), gives:
    +% perl open.pl Can't open '>>/root/renew.cgi.highlander' for appending: 'Permission d +enied' at open.pl line 6 +%
Re^3: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
by BrowserUk (Patriarch) on Dec 05, 2009 at 13:20 UTC

    Wouldn't it be nice if the $! error message came with the filename already embedded?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      How could that be done? $! is associated with errno or equivalent, but not necessarily with a file.

        I guess what you're saying here is that the low-level routines that detect the errors, only set the numeric part of $!, and that the text part is derived (looked-up) from that when asked, at which point the filename used in the failing system request is no longer available.

        But when a warn or die is called, it is able to tell us the line number of the last file read, and this is considered useful enough information to be added by default. A similar mechanism--presumably a global variabe ($.)--could be used to remember the pathname provided to the last open attempt, and used to provide that information when $! is interpolated.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: RFC: A new module to help avoid running multiple instances of the same script (via cron, for example)
by merlyn (Sage) on Dec 05, 2009 at 13:14 UTC
    That code was written pretty early. The suggestion you're making is one I started preaching a bit later.

    -- Randal L. Schwartz, Perl hacker

    The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

      Excellent, I didn't think I could put one over you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://810975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (8)
As of 2024-04-18 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found