Hi, I recently started to work with small XML files used as config or save files (FreeMind, svn, dia, ...). I normally had a first look on the XML structure to decide what to do with it. Because I like to think in Perl not XML I used a one liner to print the XML structure as Perl structure using XML::Simple and Data::Dumper.
I finally wrote today this small script so that I don't have to remember and type the one-liner (quite a long line!) repeatably.
I like of course share this with my fellow monks even if it's just a very simple script (NO! I don't only post it here so I can find it again if I need it one my many other computers!).
#!/usr/bin/perl # dumpxml: Simply dumps an XML as a Perl structure use strict; use warnings; use XML::Simple; use Data::Dumper; if (!@ARGV or grep /^-h$/, @ARGV ) { print STDERR "Usage: dumpxml <XML FILE> [ '<XML::Simple options>' +]\n"; print STDERR "Example: dumpxml file.xml 'ForceArray => 1, KeyAttr +=> \"name\"'\n"; exit 0; } my $file = shift or die; my @options = eval "@ARGV"; my $xml = XMLin( $file, @options ); print Data::Dumper->Dump( [$xml], ["FILE{'$file'}"] );

Replies are listed 'Best First'.
Re: Simple XML Dumper
by Anonymous Monk on Sep 30, 2008 at 11:12 UTC
    eval "@ARGV" is a bad idea
      I was aware about the issue with eval "@ARGV" but keep in mind that it's a local tool and only runs with the permissions of the calling user - which is allowed to execute any perl code anyway.

      It's not a CGI or suid script and not written for production environments etc.

      Not generally.

      If it's documented, it's not so bad, because whoever wants to exploit it could have run perl -e instead.

        If the script is setuid, it's considerably worse than perl -e.