#!/usr/bin/perl -w use strict; use XML::Parser; # initialize hash that will hold header info my $parser = new XML::Parser(ErrorContext => 4,Handlers => {Start => \&handle_start, End => \&handle_end, Char => \&handle_char}); my $counter =0; my @tagdesc; my %tags; # parse the file whose name we specified as a command-line parameter $parser->parsefile(shift); open(OUTPUT, ">tag.desc") or die "No open"; foreach my $keyval(keys %tags) { print OUTPUT $keyval, "\n"; } close OUTPUT; sub handle_start { my $p = shift; my $el = shift; my %attribs = @_; if($el eq 'product_data') { $counter ++; } if($counter) { push(@tagdesc, $el); } } sub handle_char { my ($p, $data) = @_; # print $data,"\n" if $counter; } sub handle_end { my $p = shift; my $el = shift; my %atrribs = @_; my $not_written = 0; if($el eq 'product_data') { $counter --; $not_written = 1;} if($not_written) { my $str = join(':',@tagdesc); @tagdesc = (); if(exists $tags{$str}) { my $cnt = $tags{$str}; $cnt++; $tags{$str} = $cnt; } else { $tags{$str} = 1; } $str = undef; $not_written = 0; } }