Here is my code:

use v5.16; use XML::Simple; my $HOME = $ENV{HOMEPATH}; my $fn = "$HOME" . "\\documents\\output.txt"; open (my $out,">$fn") or die "$fn open failed for write $!"; my @fields = qw(name medium subject url); # read in the xml from file my $site_xml = XMLin( 'C:/Users/mark/Documents/sitesout.xml', forcearray => 1 ); # print a header for the output print($out, '-' x 70, "\n"); printf ($out,"%-35s%-15s%8s%8s\n", 'name', 'medium', 'subject', 'url' +); print($out, '-' x 70, "\n"); # fetch the data, dereferencing (probably incorrectly) for my $site ( @{ $site_xml->{site} } ) { # try to print to a file printf ($out, "%-35s", $site->{ ( $fields[0] ) }->[0] ); printf ($out, "%-15s", $site->{ ( $fields[1] ) }->[0] ); printf($out, "%8s", $site->{ ( $fields[2] ) }->[0] ); printf($out, "%8s\n", $site->{ ( $fields[3] ) }->[0] ); #print to standard output #printf ("%-35s", $site->{ ( $fields[0] ) }->[0] ); #printf ("%-15s", $site->{ ( $fields[1] ) }->[0] ); #printf("%8s", $site->{ ( $fields[2] ) }->[0] ); #printf("%8s\n", $site->{ ( $fields[3] ) }->[0] ); } close $out;

I'm trying to learn something about processing XML in Perl, starting with the XML::Simple package. The entire program is in the code I've posted here. You'll see that there are 2 sections of code to print the info captured by XMLin(). One is a printf to standard output (presently commented out), the other printf to a file.

Printing to standard output gives the expected results. Printing to a file yields only 'GLOB(0x60d658)' repeated more times than I care to count, and a 0 byte file created.

I am perplexed, any pointers would be appreciated.

I'm on a Windows 7 64 bit laptop, running activestate perl v5.16


In reply to XML::Simple and output by expat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.