Processing XML with Perl | ![]() |
Michel Rodriguez |
![]() Examples: PYX one-liners |
![]() |
![]() Example: extracting information from an XML document |
Counting the number of words in an XML document.
#!/bin/perl -w use strict; my $nbw=0; foreach my $file (@ARGV) { open( XML, "pyx $file |") or die "cannot open file $file: $!"; while( <XML>) { next unless m/^-/; # skip markup next if( m/^-\\n$/); # skip line returns my @words= split; # get the words $nbw+= @words; # get the number of words in the line } close XML; } print $nbw, " words\n"; |
![]() Examples: PYX one-liners |
![]() |
![]() Example: extracting information from an XML document |