in reply to Re^6: Not able to replace element value using XML::Twig
in thread Not able to replace element value using XML::Twig

If I execute above script, I get an error because print_to_file needs a filename as parameter, but after adding that, all runs as expected. So maybe you have a very old twig version (mine seems to be from 2007-11-13). Is print_to_file() mentioned in the man page of Twig? Can you find the subroutine print_to_file if you simply search the file XML/Twig.pm with grep (should be somewhere in /usr/lib/perl5 if you have a normal linux distribution)

If not, just get a newer version from CPAN.

  • Comment on Re^7: Not able to replace element value using XML::Twig

Replies are listed 'Best First'.
Re^8: Not able to replace element value using XML::Twig
by newbie_ab (Novice) on Jan 31, 2010 at 15:14 UTC

    I was able to locate Twig.pm and it does have the print_to_file function.

    sub print_to_file { my( $t, $filename)= (shift, shift); open( TWIG_PRINT_TO_FILE, ">$filename") or croak "cannot create fi +le $filename: $!"; $t->print( \*TWIG_PRINT_TO_FILE, @_); close TWIG_PRINT_TO_FILE; return $t; }

    Twig_pm.slow,v 1.303 2006/05/26 08:07:14
    This is the Twig version in my system but the code is available in the library

      Strange. You might try the following:

      perl -Dt -m"XML::Twig" -e ''

      This only works if your perl is compiled with debugging enabled, but if it is, you will see a lot of debugging output, most lines preceded with the filename of the module perl is executing. Check that the Twig.pm you found is the Twig.pm named in most of these lines

      If it is, you also might try the following command:

      perl -Dx -m"XML::Twig" -e '' 2>&1 | grep print_to # should print: SUB XML::Twig::print_to_file = {

      This shows that the subroutine print_to_file is really parsed

      If you get both of above results, you might check the source code of your script whether there are invisible characters or a typo. You also could test this by copy-and-pasting the following line which should produce a 'cannot create file' error:

      perl -m"XML::Twig" -e '$twig=XML::Twig->new(); $twig->print_to_file() +'