|Pathologically Eclectic Rubbish Lister|
Re: Reopen a closed file for readby Marshall (Prior)
|on Apr 30, 2012 at 20:35 UTC||Need Help??|
I haven't used XML::Parser, so please excuse if this is an ignorant question, but I don't see anywhere here where the output of $parser->parsefile($xmlfile); is being saved to INTFILEout. Something appears to be missing here. I guess in the Start, End and Char routines that aren't shown.
This unless -f $intfile stuff is bizarre. There are plenty of reasons why an open could fail on an existing file. I also would take that out.
Update: On second thought, it could be that the "unless clause" is preventing the open() from even happening! I.e. the unless may apply to the open and not to the "or die" part. The kind of open() that you have will create a new file if none exists, if it does already exist, it will be essentially be "zeroed" out and a new blank file of the same name is open. In any event, I don't see the need or the intent of this "unless -f $intfile" part. See additional update below with some test code.
The close and re-open part looks ok to me. The "unless" stuff is weird.
Closing a temporary file for write and re-opening it for read is a very normal thing to do and I think you have that part right.
What are you trying to accomplish here:
Doesn't look like it does much. Something like this is useful to translate between Unix and Windows line endings (when a fiddling with a file moved between systems), but doesn't look like that is what is happening here. I guess this dummy code for some other function, but its not clear to me why you can't get the parsed XML output into the desired format in the first place without having to re-parse some intermediate file?
Another UPDATE: yep this unless is causing trouble:
If $y=1, the setx() routine (analog to the open()) does not run. The code will not open the file for output if if it already exists. I would presume that if you had strict and warnings in force, some kind of "attempted write to an unopened file handle" error would have resulted?