in reply to how to convert lexical filehand so flock will work with it

The lexical filehandle fell out of scope, auto closed, and the flock was implicitly released. The problem isn't with flock, nor with lexical filehandles. It's a matter of coping with scoping. ;)


Dave

  • Comment on Re: how to convert lexical filehand so flock will work with it

Replies are listed 'Best First'.
Re^2: how to convert lexical filehand so flock will work with it
by Anonymous Monk on Jul 05, 2013 at 07:30 UTC
    thanks, that makes sense.

      Perl::Critic is probably wrong on this one... or at least, insensitive to valid use cases. That's a frequent issue with Perl::Critic; while the book was intended to encourage thoughtfulness with respect to best practices, the module doesn't do a very good job of trying to understand why your situation might justify using an item that it considers to be a violation. The best practice really is to know what you're doing, and why. The rest is just food for thought.

      By the way, you may find this slide interesting: MJD "Only one process running at a time", from Mark Jason Dominus's File Locking Tricks and Traps talk.

      Update: I almost forgot to mention -- this employs the "lock the DATA filehandle" trick, and allows you to avoid dealing directly with flocking: Sys::RunAlone.


      Dave