home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / xyx.bat < prev    next >
Encoding:
DOS Batch File  |  2003-09-17  |  2.1 KB  |  106 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!perl -w
  14. #line 15
  15.  
  16. $VERSION = '0.35';
  17.  
  18.  
  19. =head1 NAME
  20.  
  21. xyx - convert xml to yaml or vice versa
  22.  
  23. =head1 USAGE
  24.  
  25.     xyx foo.xml > foo.yml
  26.     xyx foo.yml > foo.xml
  27.  
  28. =head1 DESCRIPTION
  29.  
  30. This program requires the Perl modules XML::Simple and YAML. It will use one of them to Load a document in the respective format, and use the other to Dump the data structure in the other format. Input content type is autodetected.
  31.  
  32. This is a trivial program and probably only useful for trivial tasks.
  33.  
  34. =head1 AUTHOR
  35.  
  36. Brian Ingerson <ingy@cpan.org>
  37.  
  38. =head1 COPYRIGHT
  39.  
  40. Copyright 2002, Brian Ingerson - All rights reserved
  41.  
  42. You may use this hack under the same terms as Perl itself.
  43.  
  44. =cut
  45.  
  46. use strict;
  47. use YAML;
  48. use XML::Simple;
  49.  
  50. my @serieskeys = ();
  51.  
  52. my $data = join '', <>;
  53. my %opts;
  54.  
  55. if ($data =~ /^\s*</) {
  56.     my $xml = XMLin(
  57.     $data,
  58.     keeproot=>1,
  59.     noattr=>1,
  60.     keyattr=>[@serieskeys],
  61.     suppressempty=>''
  62.     );
  63.     print Dump($xml);
  64. }
  65. else {
  66.     for my $object (Load($data)) {
  67.     print XMLout($object,
  68.              keeproot => 1,
  69.              noattr => 1,
  70.             );
  71.     }
  72. }
  73.  
  74. BEGIN {
  75.     my %options = map {("-$_", 1)}
  76.       qw(help);
  77.     my @STDIN = ();
  78.     if (@ARGV and
  79.         $ARGV[-1] !~ /^-/
  80.        ) {
  81.         die "Invalid input file '$ARGV[-1]'\n"
  82.           unless -f $ARGV[-1];
  83.         push @STDIN, pop @ARGV;
  84.     }
  85.  
  86.     for my $arg (@ARGV) {
  87.         if ($arg =~ /^-s(?:erieskeys)?=(\w.*)$/) {
  88.             for my $key (split ',', $1) {
  89.                 push @serieskeys, $key;
  90.             }
  91.         }
  92.         elsif ($options{$arg}) {
  93.             $opts{$arg} = 1;
  94.         }
  95.         else {
  96.             die "Invalid option '$arg'\n";
  97.         }
  98.     }
  99.  
  100.     @ARGV = @STDIN;
  101. }
  102.  
  103.  
  104. __END__
  105. :endofperl
  106.