Dave Adams wrote:
When generating a file with XML::Writer the script certainly builds the
file but when I go to test for it, it fails. Does anyone have a reason why?
How do I create a file that I can use in the rest of my script?
use XML::Writer;
use IO::File;
my $output = new IO::File(">test.xml");
my $writer = new XML::Writer(OUTPUT => $output);
$writer->startTag("greeting","class" => "simple");
$writer->characters("Hello, world!");
$writer->endTag("greeting");
$writer->end();
$output->close();
#Test to make sure this file exist before preceding
if (! -r $output) {
print ("ERROR: can't read /$output XML file.");
}
Please, always
use strict;
use warnings;
at the start of your programs. That will find a lot of simple problems.
You're testing whether your file handle $output is opened to a read-permitted
file. First of all you opened it write-only so you won't be able to read from
the handle even if you have read permissions. Secondly you've closed the handle,
so it's not referring to a file at all any more.
Just open the file for read, checking any errors you get. If you don't
have read permission then the open will fail:
open my $in, 'test.xml' or die "ERROR: can't read XML file: $!";
while (<$in>) {
print;
}
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/