rheaton has asked for the wisdom of the Perl Monks concerning the following question:
I have a file that is being used to lock a process that contains only the values of 1 and 0 in it. I have tried opening the File and $value = <file_name> as well as foreach(<file_name>){$value = $_}. I do not only want to `cat $file_name` because if the file is unreadable I want to be able to trap the error. What are my alternatives? I need to be able to do the following but for some reason it is not working...
STAGE_DIM: if(not(open(process_lock, "+>$proc_lock"))){ goto STAGE_DIM; sleep 1; } $lock_val = <process_lock>; #`cat $proc_lock`; print "Value=*$lock_val*\n"; if( $lock_val == 1) { close(process_lock); sleep 1; goto STAGE_DIM; } else { ... }
The Value read is always "". The only way thus far, I have been able to read the contents of the file was to $lock_val = `cat $proc_lock`; but this leaves the chance that the file could be unreadable because another Process has it locked open. Any ideas would be appreciated. Thanks. rheaton
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Read
by Fletch (Bishop) on Mar 12, 2007 at 13:06 UTC | |
by rheaton (Acolyte) on Mar 12, 2007 at 13:31 UTC | |
by rheaton (Acolyte) on Mar 12, 2007 at 13:36 UTC | |
by Fletch (Bishop) on Mar 12, 2007 at 14:03 UTC | |
by diotalevi (Canon) on Mar 12, 2007 at 16:21 UTC | |
|
Re: File Read
by derby (Abbot) on Mar 12, 2007 at 14:48 UTC | |
by rheaton (Acolyte) on Mar 12, 2007 at 15:51 UTC | |
by Fletch (Bishop) on Mar 12, 2007 at 16:51 UTC | |
by Anno (Deacon) on Mar 12, 2007 at 17:24 UTC | |
|
Re: File Read
by MonkE (Hermit) on Mar 12, 2007 at 13:45 UTC | |
by rheaton (Acolyte) on Mar 12, 2007 at 14:06 UTC |