Well, first, define "silly" :-)

Next, I'd suggest pulling out the mv call and making it a rename call after the system. More portable, and easier to read, IMO.

Then the actual reformat... that's debatable. I expect that xmllint, being C code, might be faster than trying to use something else (I'd probably use XML::Twig if it mattered, but I usually wouldn't concern myself with trying to make XML pretty - check the source to last hour of cb at some point to see how ugly the html I generate is :-)). There's a point of diminishing returns either way here: for small XML files, the cost of calling out to xmllint may overwhelm an implementation done in XML::Twig, on the other hand, the cost of developing with XML::Twig, given that you already have a working version with xmllint, is going to be significant, too. For larger XML files I would expect xmllint to perform better at this task.

By the way, if you can avoid the shell altogether, that's a plus, too. Since you're redirecting the output, this can be annoyingly painful to do, so check if xmllint can take an option for output file.

local $ENV{XMLLINT_INDENT} = "\t"; my $linted = "$outfile-lint"; # for readability unlink $linted; system( # here is how we avoid the shell: don't use a string. Use a li +st qw(xmllint --format --output), $linted, $outfile ); # don't forget to check return code! rename $linted, $outfile;
Hope that helps,


In reply to Re: Calling xmllint better than using a system() by Tanktalus
in thread Calling xmllint better than using a system() by itsscott

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.