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

Hey Monks,

I wrote a this morning trying to read b/w xml tags. However, i am having a little problem. The specified tags I want to read is been picked up but the content of the tag is not been read. Can any monk kindly help me solve this problem?

if (open(DBASE, $path."database.txt")) { while(<DBASE>) { chomp; if ($_ =~ /\.xml/) { if (open(XFILE, $_)) { while (<XFILE>) { chomp; if ($_ =~ /\<name\>|\<\/name\>/) { print (LIST "$_\n"); } } } } } }
Thanks

Replies are listed 'Best First'.
Re: Reading B/w Tags
by planetscape (Chancellor) on Mar 13, 2006 at 16:08 UTC

    I suggest you use an XML module (perhaps one listed here or here), rather than try to roll your own, for much the same reasons that you would be better off using an HTML parser to handle HTML than trying to make do using regexes.

    HTH,

    planetscape
Re: Reading B/w Tags
by CountOrlok (Friar) on Mar 13, 2006 at 16:06 UTC
    Your regex for matching the "name" tag will not work. Do look into using a module like XML::Simple. It would make your life easier.
    -imran