Xxaxx has asked for the wisdom of the Perl Monks concerning the following question:
I believe I have the fileopen and return working. At least is seems to be working.
The part I'm messing up on is the file locking part.
From flock manpage:
Below was my attempt at making this work. If a kind hearted monk could help unscramble this I'd appreciate it.sub lock { flock(MBOX,LOCK_EX); # and, in case someone appended # while we were waiting... seek(MBOX, 0, 2); } sub unlock { flock(MBOX,LOCK_UN); } open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}") or die "Can't open mailbox: $!"; lock(); print MBOX $msg,"\n\n"; unlock();
Thanks in advance. Claudesub fileopen { my($filename) = @_; local *MW; my($openokay) = open(MW,"+<$filename"); if (!$openokay) { return 0; } lock(*MW); seek(MW,0,0); return *MW; } sub lock { my($nick) = @_; flock({$nick},LOCK_EX); # and, in case someone appended # while we were waiting... seek({$nick}, 0, 2); } sub unlock { my($nick) = @_; flock({$nick},LOCK_UN); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: flock with anonymous filehandle
by wog (Curate) on Jun 09, 2001 at 05:10 UTC | |
|
Re: flock with anonymous filehandle
by HamNRye (Monk) on Jun 09, 2001 at 23:55 UTC | |
by wog (Curate) on Jun 10, 2001 at 00:06 UTC | |
by Xxaxx (Monk) on Jun 10, 2001 at 06:32 UTC | |
by Anonymous Monk on Jun 11, 2001 at 13:24 UTC |