in reply to create an xml file from column file

If your input does not contain <, &, or ]]>, you do not need anything special:
#!/usr/bin/perl use warnings; use strict; use constant { WORD => 0, TYPE => 1, }; my @annotations; while (<DATA>) { my ($word, $type) = split; $type =~ s/.-*//; push @annotations, [ $word, $type ]; } print '<text>'; print join ' ', map $_->[WORD], @annotations; print '</text>'; for my $annotation (@annotations) { print '<annotation>'; print '<type>', $annotation->[TYPE], '</type>'; print '<text>', $annotation->[WORD], '</text>'; print '</annotation>'; } __DATA__ how B-NP are I-NP you I-NP
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: create an xml file from column file
by lakssreedhar (Acolyte) on Jul 24, 2013 at 12:10 UTC

    how would it be if my input was

    how o B-NP are o o you o I-NP
    now i need annotation tags only for those words which has B-NP and I-NP in the third column

      I pressed the wrong button and shrunk the code accidentially. It still should do what you want.

      use strict; use warnings; print "<text>",join(" ",map{/^(\w+).*?(B-NP|I-NP)?$/; $a.="<annotation><type>NP</type><text>$1</text></annotation>\n"if$2;$1 +}<DATA>),"<text>\n$a"; __DATA__ how B-NP are you I-NP really

        if i my input was this

        how o B-NP are o I-NP you o I-NP some o o really o B-GP
        and i want the output as <key="type">NP</key><text>how are you</text><key="type">GP</key><text>really</text> That is i want the whole text from B-NP to I-NP to occur in between text open and close tags.