jcvivar has asked for the wisdom of the Perl Monks concerning the following question:

Hi!. I have many XML files and a fixed list of words in a text file ("dictionary"). I want to compare each XML file with the dictionary and save another file. This new file must contain the same words of the dictionary and the frequency of ocurrence in the XML file (could be zeros). Is it possible to do this in Perl? Thank you for any help.

Replies are listed 'Best First'.
Re: File comparisons and word count
by moritz (Cardinal) on Oct 15, 2009 at 17:12 UTC

    Yes, it is. Reading text files is simple, and there are lots of good modules out there for reading XML files, like XML::LibXML or XML::Twig.

    If you don't know any perl, reading perlintro should help you. If you have more specific questions, feel free to ask (but show us what you've tried, and tell us how it did not match your expectations).

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: File comparisons and word count
by Akoya (Scribe) on Oct 15, 2009 at 19:27 UTC

    I would recommend storing each of your "dictionary" words in an associative array (hash), incrementing the value each time the word is found. Once all your XML files have been parsed, it is a simple matter to print each key and value from the hash.