in reply to Re: XML::Twig Help
in thread XML::Twig Help

The djn-geo tag is in there, for example:

<djn-geo> <\c>R/ALT\<\/c> <\c>R/ARA\<\/c> </djn-geo>

My code now reads:

#!/usr/bin/perl use strict; use warnings; chomp(my $enter = <STDIN>); my @fields = split(/ /, $enter, 9999); use XML::Twig; open (FILE, $fields[1]); my $file = <FILE>; my $t= XML::Twig->new( twig_roots => { 'djn-geo' => 1}); $t->parsefile($file); open(STDOUT, ">$fields[2]"); $t->print;

And I get the error:

Unsuccessful stat on filename containing newline at C:/Perl/site/lib/XML/Twig.pm line 684, <FILE> line 1. Couldn't open version="1.0" encoding="ISO-8859-1"?> : Invalid argument at C:\Documents and Settings\odeab\My Documents\Exec_Extract\tw iggie.pl line 10 at C:\Documents and Settings\odeab\My Documents\Exec_Extract\twiggie.pl line 10

Replies are listed 'Best First'.
Re^3: XML::Twig Help
by marto (Cardinal) on Jul 06, 2010 at 15:47 UTC

    You still aren't checking that open worked.

Re^3: XML::Twig Help
by AndyZaft (Hermit) on Jul 06, 2010 at 16:17 UTC
    Well, before we go further, Twig will tell you that it is not well-formed, likely because  <\c> is not a valig tag. If your XML is filled with tags like that even if you manage to open the files themselves you will run into problems.

    From your code I assume you are trying to type in a few XML filenames and the process them. First problem, if you only have 1 XML as a test, you need to open fields[0], otherwise open will fail with uninitialized value. Then once you fix that you are trying to open a file that's named the first line of the first file. You also don't need to open a file for XML::Twig, the module can do it itself. I would suggest starting simple, like take 1 XML file and create a simple perl script that opens it and does something with it. Something along the lines of:

    #!/usr/bin/perl use strict; use warnings; use XML::Twig; my $file = "yourxmlfilename.xml"; my $t= XML::Twig->new( twig_roots => { 'djn-geo' => 1}); $t->parsefile($file); $t->print;
    Based on more assumptions looking at your code that you are trying to output to the second file given in the input, you can redirect later or at command line. Although I'm not sure how that behaves on windows nowadays. In any case you can also use  $t->print_to_file($anotherfilename) and many other ways.