in reply to newbie regex question: substituting repeating occurences for different replacements
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
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<row>a</row> <row2>b</row2>
-----#! /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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) 2Re: substituting repeating occurences ... (XML::Generator::DBI / DBD::AnyData version)
by jeffa (Bishop) on Jul 09, 2003 at 22:05 UTC |