Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^6: create an xml file from column file

by lakssreedhar (Acolyte)
on Jul 25, 2013 at 09:19 UTC ( [id://1046304]=note: print w/replies, xml ) Need Help??


in reply to Re^5: create an xml file from column file
in thread create an xml file from column file

is it possible to do without CSV .The code i wrote is below.But the required output is not coming

$out=" "; my @text; while(<>) { chomp; @arr=split(/\s+/,$_); push @r,$arr[0]; push @e,join' ',($arr[0],$arr[2]); } print '<text>'; print join ' ',@r; print '</text>'; print"\n"; for my $a (@e) { @q=split(/\s/,$a); if($q[1]=~/^B-/) { $p=$'; $m=$q[0] if( $q[1] =~/^B-/ or $q[1]="o"); $out.="<annotation>\n<key=type>$p</type>\n<text>$m</text>\n</annotatio +n>\n"; } } print"$out\n";

Replies are listed 'Best First'.
Re^7: create an xml file from column file
by hdb (Monsignor) on Jul 25, 2013 at 09:46 UTC

    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;

      It is working but this error is popping up Use of uninitialized value in pattern match (m//) at f.pl line 14, <$words> line 18.

        Is line 18 empty in your file? You would need to add code to skip empty lines.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1046304]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found