Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^7: create an xml file from column file

by hdb (Monsignor)
on Jul 25, 2013 at 09:46 UTC ( #1046310=note: print w/replies, xml ) Need Help??

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

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

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046310]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-12-12 01:49 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (322 votes). Check out past polls.