Professional Web Applications Themes

XML::Twig print to file gives expected results except for failure return value - PERL Modules

(I had some conversation in c.l.p.m about this originally but it's no longer a Perl coding problem so I'm moving it here.) Using XML::Twig I'm reading in an XML file, adding an element to it and writing the result out again. The file is correctly written, but the return code from the "print" method denotes failure. The Twig doentation doesn't indicate that behaviour; can someone help me debug this further? --------- code to show the error ---------- use strict; use warnings; use XML::Twig; # Get the XML file my $fdtwig = new XML::Twig; $fdtwig->pfile('F:\p\XMLin.XML'); my $fd = $fdtwig->root; # Create ...

  1. #1

    Default XML::Twig print to file gives expected results except for failure return value

    (I had some conversation in c.l.p.m about this originally but it's no
    longer a Perl coding problem so I'm moving it here.)

    Using XML::Twig I'm reading in an XML file, adding an element to it
    and writing the result out again. The file is correctly written, but
    the return code from the "print" method denotes failure. The Twig
    doentation doesn't indicate that behaviour; can someone help me
    debug this further?

    --------- code to show the error ----------
    use strict;
    use warnings;

    use XML::Twig;

    # Get the XML file
    my $fdtwig = new XML::Twig;
    $fdtwig->pfile('F:\p\XMLin.XML');
    my $fd = $fdtwig->root;

    # Create a new twig and paste it into the XML doc
    my $stuff = "somestuff";
    my $elt = new XML::Twig::Elt('stuff',$stuff);
    $elt->paste('last_child',$fd);

    # Write the modified XML doent to a new file
    open XMLOUT, '>F:\p\xmlout.xml';
    $fdtwig->print(\*XMLOUT) or
    die "Failed to write modified XML file:$!\n";

    close XMLOUT;
    ------------------------------

    The result of this (running with ActiveState Perl 5.8.2) is

    F:\p>perl tryit.pl
    Failed to write modified XML file:Bad file descriptor

    But the file "xmlout.xml" is correctly created with the expected
    contents. I debugged the program and verified that the return value
    is "false".

    Henry Law <>< Manchester, England
    Henry Law Guest

  2. #2

    Default Re: XML::Twig print to file gives expected results except for failure return value

    On Sun, 25 Apr 2004 20:55:20 +0200, Michel Rodriguez
    <mirodxmltwig.com> wrote:
    >Actually the doc doesn't specify the return value of print, so really
    >there is no point in checking it.
    >Does this help?
    Perfectly and excellently. The guys over in comp.lang.perl.misc would
    have one's hide if one didn't check a return value so I thought I'd
    better; now that the oracle himself has told me that I don't need to
    I'll carry right on ahead.

    Great tool, by the way. Much more intuitive and easy to understand
    than some of the other XML prs I've used.

    Henry Law <>< Manchester, England
    Henry Law Guest

  3. #3

    Default Re: XML::Twig print to file gives expected results except for failure return value

    On Sun, 25 Apr 2004 20:55:20 +0200, Michel Rodriguez
    <mirodxmltwig.com> wrote:
    >Actually the doc doesn't specify the return value of print, so really
    >there is no point in checking it.
    Another thought, though: it's strange that $! is being returned with
    "Bad file descriptor".

    Henry Law <>< Manchester, England
    Henry Law Guest

  4. #4

    Default Re: XML::Twig print to file gives expected results except for failurereturn value

    Henry Law wrote:
    > Using XML::Twig I'm reading in an XML file, adding an element to it
    > and writing the result out again. The file is correctly written, but
    > the return code from the "print" method denotes failure. The Twig
    > doentation doesn't indicate that behaviour; can someone help me
    > debug this further?
    Actually the doc doesn't specify the return value of print, so really
    there is no point in checking it.

    By construction a twig can always be exported, so the only problem that
    can happen is if the print itself doesn't succeed. If you really want to
    check it, then you can write:

    print XMLOUT $fdtwig->sprint

    Does this help?

    --
    Michel Rodriguez
    Perl &amp; XML
    [url]http://www.xmltwig.com[/url]

    Michel Rodriguez Guest

  5. #5

    Default Re: XML::Twig print to file gives expected results except for failurereturn value

    Henry Law wrote:
    > Another thought, though: it's strange that $! is being returned with
    > "Bad file descriptor".
    I have no idea where this $! comes from, as the print apparently
    succeeded, so it's hard for me to comment on it ;--). The doc for $!
    states that it is "meaningful only immediately after a failure", so I
    wouldn't worry about it.

    He also wrote:
    > Perfectly and excellently. The guys over in comp.lang.perl.misc
    > would have one's hide if one didn't check a return value so I thought
    > I'd better; now that the oracle himself has told me that I don't need
    > to I'll carry right on ahead.
    Thanks, now they will go after me!
    > Great tool, by the way. Much more intuitive and easy to understand
    > than some of the other XML prs I've used.
    Thanks.

    --
    Michel Rodriguez
    Perl &amp; XML
    [url]http://www.xmltwig.com[/url]

    Michel Rodriguez Guest

Similar Threads

  1. #39412 [NEW]: base64_decode does not return FALSE on failure
    By phpbugs at staznosti dot sk in forum PHP Bugs
    Replies: 2
    Last Post: November 7th, 02:45 PM
  2. cfif not giving expected results
    By sh100 in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: July 13th, 12:58 PM
  3. twig requires 5.004, I am using Windows v5.6.1, which twig do I need
    By Sherman Willden in forum PERL Miscellaneous
    Replies: 1
    Last Post: July 24th, 11:55 PM
  4. DB2 Select - how to return a range of results
    By Igor Pool in forum IBM DB2
    Replies: 2
    Last Post: July 15th, 01:09 PM
  5. Return Search Results on the Same Page
    By shell in forum ASP Database
    Replies: 2
    Last Post: July 14th, 11:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139