twdgt has asked for the wisdom of the Perl Monks concerning the following question:
I am attempting to do the following: use the XML::Parser to extract specific information into a text file and then by selective regwx, place the extracted information into another formatted text document. Where I am having an issue is reading the first text file after it has been created and closed. For some reason I cannot read from the reopened INTFILEin or write to FMTFILE within the "while" loop (relevant code below). I did try the same steps not using the XML parser (using a print to INTFILEout of character strings) and had no problem writing to the file.
# open intermediate file for pass of XML file open (INTFILEout, '>', $intfile) or die ("Cannot open file $intfile") unless -f $intfile; # parse thru XML file into intermediate file my $parser = new XML::Parser; $parser->setHandlers( Start => \&startElement, End => \&endElement, Char => \&characterData, Default => \&default); $parser->parsefile($xmlfile); # close intermediate file from first pass of XML file close INTFILEout; # reopen intermediate file for load into formatted output file open (INTFILEin, '<', $intfile) or die ("Cannot open file $intfile") unless -f $intfile; open (FMTFILE, '>', $frmtfile) or die ("Cannot open file $frmtfile") unless -f $frmtfile; # processing intermediate file into formatted file while ($linein = <INTFILEin>){ chomp $linein; print FMTFILE "$linein\n"; } # close files used to create formatted file close INTFILEin; close FMTFILE;
Any assistance or guidance is appreciated. Thanks...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reopen a closed file for read
by Marshall (Canon) on Apr 30, 2012 at 20:35 UTC | |
|
Re: Reopen a closed file for read
by toolic (Bishop) on Apr 30, 2012 at 20:06 UTC |