Dear Monks
I have a file which is being written by a sub in one module, let's call it Write() in Write.pm. My script then later calls &Check() in Check.pm which opens that same file, runs through it and performs a series of checks on each line to make sure everything is in order. However, I think the file is still being written when I call &Check() since for a line near the end of the file I keep getting the error
Argument "1.21633032597832 + 1.8765165060" isn't numeric in numeric lt
+ (<) at Check.pm line x, <CONFIG> line y.
The line should read '1.21633032597832 + 1.8765165060i and indeed it does when I open and check the config file. There are also hundreds of lines almost identical to this one and they don't cause a problem (there's a regex to capture imaginary numbers to divert them away from the numerical comparison mentioned in the error). This problem also goes away when I insert sleep(3) between &Write() and &Check()
So..
- Is there a way to tell whether the file is still being written?
- Does it sound like this is the problem or could there be something I'm overlooking?
I've tried fiddling around and repeatedly inserting stat() and sleep(), but that doesn't seem to report any difference between when the file is still being written (I get this error) and when it's finished writing. I'm expicitly close()ing my filehandles at the end of the
&Write() and
&Check(), though they should be closed implicitly anyway, shouldn't they, since they go out of scope? (I naïvely thought that the close would wait till they're finished writing..)
Sorry for the rather rambling question, this is a problem that's caught me out a few times in various projects so it'd be good to figure it out
Cheers
why_bird
........
Those are my principles. If you don't like them I have others.
-- Groucho Marx
.......
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.