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.
Hope that helps,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;
In reply to Re: Calling xmllint better than using a system()
by Tanktalus
in thread Calling xmllint better than using a system()
by itsscott
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |