Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^7: create an xml file from column file

by hdb (Prior)
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;


Comment on Re^7: create an xml file from column file
Download Code
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 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
Node Status?
node history
Node Type: note [id://1046310]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2015-07-28 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls