Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I don't understand this line from your code

It checks the reason for why flock failed instead of assuming it's because the file is already locked.

flock returns error EWOULDBLOCK on unixy systems and error 33 on Windows.

it seems like the file handle ($fh) needs to be a global variable, so I used 'our' instead of 'my'. If I use 'my'

Correct. In my version, the END sub kept it alive.

I'd like to add something like this: use Highlander qw( :verbose );

First, :name traditionally has a meaning already. Dashes are usually used for options. As a bonus, -foo means the same thing as '-foo' even when strict is in use, so less quoting is needed.

Secondly, suppressing the message by default is a bad idea. The option should silent the message when provided.

On to the good stuff,

use Highlander -silent;
is the same as
BEGIN { require Highlander; Highlander->import(-silent); }

so you need to create a method called import that looks like

my $opt_silent; sub import { my $class = shift; $opt_silent = 0; for (@_) { if ($_ eq -silent) { $opt_silent = 1; } else { require Carp; Carp::carp("Unrecognized symbol $_"); } } }

But it won't work. The problem is that the module has already been executed (and the lock obtained) by require before import is called.

But you know what? The option isn't really needed. The message can always be suppressed on the command line by using output redirection.

I'm not planning to upload this to CPAN. It seems too simple to bother.

Yet you had to write it and needed help to do so. You can also credit whoever you want in the docs.


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

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (4)
    As of 2019-11-15 05:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Strict and warnings: which comes first?



      Results (80 votes). Check out past polls.

      Notices?