Your data currently appears to be close to YAML format, so if you did convert it to YAML, you could do something like this:
Output:use strict; use warnings; use YAML; my $stuff = <<YAML; --- ABC: DEF: - GHI YAML my $perl_structure = Load $stuff; printit ($perl_structure); sub printit{ my $this = shift; if (ref $this eq "" ){ print $this; return; } if (ref $this eq "ARRAY"){ print "<value>"; printit ($_) for @$this; print "</value>\n"; return; } #print "Got " . ref ($this) . "\n"; for my $k (keys %$this){ print "<$k>\n"; printit($_) for $this->{$k}; print "</$k>\n"; } }
However - if your input is even slightly more complicated than this, I would recommend using a "real" XML generator module. (XML::Simple if you dont have experience with these).<ABC> <DEF> <value>GHI</value> </DEF> </ABC>
“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.”
― Jon Ribbens
In reply to Re: how to convert tab separated text lines into xml files
by NetWallah
in thread how to convert tab separated text lines into xml files
by osprofi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |