in reply to Re^6: create an xml file from column file
in thread create an xml file from column file
At your own risk, splitting on tab:
use strict; use warnings; open my $words, "<", "words.txt" or die "Cannot open words.txt: $!\n"; my $lasttype; my @text; while( <$words> ) { chomp; my @row = split /\t/; my $text = $row[0]; my $type = ( $row[-1] =~ /\w-(\w+)/ ) ? $1 : ""; $lasttype = $type unless @text; # special treatment for first +row if( $type eq $lasttype ) { push @text, $text; } else { print '<key="type">'."$lasttype</key><text>@text</text +>\n" if $lasttype; $lasttype = $type; @text = ( $text ); } } # print what's left over when all input read print '<key="type">'."$lasttype</key><text>@text</text>\n" if $lasttyp +e; close $words;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: create an xml file from column file
by lakssreedhar (Acolyte) on Jul 25, 2013 at 11:02 UTC | |
by hdb (Monsignor) on Jul 25, 2013 at 11:04 UTC |