This got me thinking... I often create xml but always with the first tag being different for each .. well where the tag <row> exists here I normally only need

<row>a</row> <row2>b</row2>
So here is my stab at doing this with XML::Simple. Please comment on how I can refine this... but I do know it outputs what was asked for... ;-D

#! /usr/bin/perl use strict; use warnings; use XML::Simple; use Data::Dumper; my (%h); my $xs = XML::Simple->new( keeproot => 1, noattr => 1, noescape => 1); open (FILE, ">>./Test.xml") or die "Cannot create Test.xml: $!\n"; while (<DATA>) { delete $h{row}; my $count = 0; chomp; my @line = split(/;/); foreach my $var (@line) { $count++; my $tag = "col" . $count; $h{'row'}{$tag} = $var; } print Dumper(\%h); print FILE $xs->XMLout(\%h); } close(FILE); __DATA__ a;b;c;d;e f;g;h i; j

-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: newbie regex question: substituting repeating occurences for different replacements by AcidHawk
in thread newbie regex question: substituting repeating occurences for different replacements by RuyLopez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.