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

Greetings, I'm fairly new to Perl, so please forgive me if this is a stupid question.

I have a file that contains blocks of info like this:

Date: blabla
Subject:blabla

and so forth, all the same fields, delimited by colons and separated into 'paragraphs.' I have to chunk this info into separate XML files, using the field keys as tags and the record values as elements.

I've researched XML::Writer, and will use that to generate the actual XML code, but how do I read thru the input file and create a separate XML file for each 'paragraph' of data?

Thanks much in advance,
Roger (RT486)

Replies are listed 'Best First'.
Re: Writing XML files from list
by sauoq (Abbot) on Dec 05, 2003 at 20:05 UTC
    but how do I read thru the input file and create a separate XML file for each 'paragraph' of data?

    The basic approach is simply to read one paragraph, open a file, write your XML into it, close the file, and repeat as necessary.

    If you are asking us how to recognize the end of your blocks or how to read one block at a time, that depends on your data. You may be able to change $/, the input record separator to help you. For instance, if your blocks are separated by one or more blank lines, you can set $/ = ''; to read one paragraph at a time.

    -sauoq
    "My two cents aren't worth a dime.";
    
      Thank you, that makes sense. I'll try it.

      RT486