Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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
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 cooling their heels in the Monastery: (6)
As of 2014-12-29 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (187 votes), past polls