lib/scripts/yxml.pl
changeset 35060 6088dfd5f9c8
parent 35059 acbc346e5310
parent 35054 a5db9779b026
child 35061 be1e25a62ec8
child 35117 eeec2a320a77
equal deleted inserted replaced
35059:acbc346e5310 35060:6088dfd5f9c8
     1 #
       
     2 # Author: Makarius
       
     3 #
       
     4 # yxml.pl - simple XML to YXML converter
       
     5 #
       
     6 
       
     7 use strict;
       
     8 use XML::Parser;
       
     9 
       
    10 binmode(STDOUT, ":utf8");
       
    11 
       
    12 sub handle_start {
       
    13   print chr(5), chr(6), $_[1];
       
    14   for (my $i = 2; $i <= $#_; $i++) {
       
    15     print ($i % 2 == 0 ? chr(6) : "=");
       
    16     print $_[$i];
       
    17   }
       
    18   print chr(5);
       
    19 }
       
    20 
       
    21 sub handle_end {
       
    22   print chr(5), chr(6), chr(5);
       
    23 }
       
    24 
       
    25 sub handle_char {
       
    26   print $_[1];
       
    27 }
       
    28 
       
    29 my $parser = new XML::Parser(Handlers =>
       
    30   {Start => \&handle_start,
       
    31     End => \&handle_end,
       
    32     Char => \&handle_char});
       
    33 
       
    34 $parser->parse(*STDIN) or die $!;
       
    35