Semi-tested (I don't know Text::CSV so I might not be using it as well as possible). You'll be much happier if you use some more robust approaches to XML (XML::LibXML), CSV, and file handling. This might not be final but it's worth playing around with the pieces and approach.

use strict; use warnings; use XML::LibXML; use Text::CSV; open my $dip_file, ">>", "C:/director/DIPFILE.TXT" or die "Couldn't open DIP file for appending: $!"; open my $dip_log, ">>", "C:/director/DIPLOG.TXT" or die "Couldn't open DIP log for appending: $!"; my $csv = Text::CSV->new; # glob is a built-in, you don't need to "use File::Glob." my @dipfile = glob('C:/director/*.xml'); my $parser = XML::LibXML->new(); # set options for $parser here if needed, like $parser->recover(1) for # messed up XML. for my $xml_file ( @dipfile ) { my $doc = $parser->parse_file($xml_file); my ( $default_name ) = $doc->findnodes("//defaultName"); my ( $default_description ) = $doc->findnodes("//defaultDescriptio +n"); my ( $report_execution_time ) = $doc->findnodes("//reportExecution +Time"); $csv->combine( $xml_file, $default_name ? $default_name->textContent : "", $default_description ? $default_description->textCo +ntent : "", $report_execution_time ? $report_execution_time->te +xtContent : "", ); # Update: print $csv->string, "\n"; # To see it in the terminal. $dip_file->print( $csv->string, "\n" ); $dip_log->print( $csv->string, "\n" ); }

In reply to Re: Reading XML File Hash in text by Your Mother
in thread Reading XML File Hash in text by drodinthe559

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.