#!/usr/lib/perl use strict; use warnings; use XML::Writer; my $out; my $xml = XML::Writer->new(OUTPUT => \$out, DATA_MODE => 1, DATA_INDENT => ' '); $xml->xmlDecl(); $xml->startTag('doc'); while () { chomp; next if !length; my ($bibData, $quote, $primary, $sec) = / ^([^"]* "[^"]+"[^"]*) ([^\@]+) \@([^%]+) \%(.*) /x; $xml->startTag('entry'); $xml->dataElement(bib => $bibData); $xml->dataElement(quote => $quote); $xml->dataElement(primary => $primary); $xml->dataElement(sec => $sec); $xml->endTag(); } $xml->endTag(); $xml->end(); print $out; __DATA__ Leyson, Captain Burr. "With or Without Gadgets." Boys' Life. Nov 1949. p. 6. "An old-timer knew what he had to do in a jam. He didn't need hundreds of those gadgets to guide him to safety." @gauge %trivial "The Battle Against Baldness." Kiplinger's Personal Finance. Feb 1949. "A little home hair-cutter gadget--a comb with a razor attached-- has zipped its way into fame in recent months. Barbers pooh-pooh it as a threat, but sales are going strong." @tool %american #### Leyson, Captain Burr. "With or Without Gadgets." Boys' Life. Nov 1949. p. 6. "An old-timer knew what he had to do in a jam. He didn't need hundreds of those gadgets to guide him to safety." gauge trivial "The Battle Against Baldness." Kiplinger's Personal Finance. Feb 1949. "A little home hair-cutter gadget--a comb with a razor attached-- has zipped its way into fame in recent months. Barbers pooh-pooh it as a threat, but sales are going strong." tool american