aakikce has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks,
I am working on a tagged text to XML conversion
My perl script using xml::twig is working well. (I have include strict and warnigs). But I converted the source to exe using perlapp. But it doesn't work (partially I get output). It shows errors like
use of uninitiated value in pattern and also use of uninitiated value in scalar assignment.
use strict; use warnings; use XML::Twig; undef $/; open (FIN, "<$ARGV[0]") || die "can't open input file"; my $content = <FIN>; $content = "<chapter>\n".$content."\n</chapter>"; $content =~s/ ([^ >]+>)/$1/gsi; $content =~s/ ([^ >]+>)/$1/gsi; $content =~s/&#/@#/gsi; my $t = new XML::Twig (twig_handlers => { 'chapterhead' => sub { $_->set_tag('title') }, 'bodytext' => sub { $_->set_tag('para') }, 'sup' => sub { $_->set_att('aid:cs +tyle'=>'sup') }, 'sub' => sub { $_->set_att('aid:cs +tyle'=>'sub') }, }, pretty_print => 'indented' ); $t->parse($content); #******************************** &stags($t->root, 'ahead', 'section'); # first leve +l section my @secheads = $t->get_xpath('//section'); # second level +section foreach my $sechead (@secheads) { &stags($sechead, 'bhead', 'sub-section'); } # ******************************** &groupingelements('outlinetext', '<outlinetext>*', 'outline-box'); $t->change_gi('outlinetext','para'); $t->change_gi('ahead', 'title'); $t->change_gi('bhead', 'title'); &insertelements('//quote', 'para'); # ************** Normal Lists ******************* &groupingelements('bulletlist', '<bulletlist>*<Bulletsublist>*<Nmbersu +blist>*<bulletlist>*', 'listbullet'); &groupingelements('Bulletsublist', '<Bulletsublist>*', 'listbullet'); my @lstbulls= $t->findnodes('//listbullet'); foreach my $lb (@lstbulls) { $lb->set_tag('list'); $lb->set_att(type => 'bullet'); my @items = $lb->get_xpath(qq{//bulletlist}); foreach my $itm (@items) { $itm->set_tag('item'); $itm->insert('para'); } my @sitems = $lb->get_xpath('//Bulletsublist'); foreach my $itm (@sitems) { $itm->set_tag('item'); $itm->insert('para'); } } # **************** Boxed Lists******************** &groupingelements('Boxedbulletlist', '<Boxedbulletlist>*<BoxedBulletsu +blist>*<Boxedbulletlist>*', 'boxedlistbullet'); &groupingelements('BoxedBulletsublist', '<BoxedBulletsublist>*', 'boxe +dlistbullet'); my @blstbulls= $t->findnodes('//boxedlistbullet'); foreach my $lb (@blstbulls) { $lb->set_tag('blist'); $lb->set_att(type => 'bullet'); my @items = $lb->get_xpath(qq{//Boxedbulletlist}); foreach my $itm (@items) { $itm->set_tag('item'); $itm->insert('para'); } my @bitems = $lb->get_xpath('//BoxedBulletsublist'); foreach my $itm (@bitems) { $itm->set_tag('item'); $itm->insert('para'); } } # ************************************ ######## nested list move in item my @items = $t->get_xpath('//list/item'); foreach my $itm (@items) { my $more_text = $itm->next_sibling; # if fails +, $more_text becomes so undef, if ($more_text && ($more_text->tag eq 'list')) # so the condition +like this { $more_text->move('last_child', $itm); } } # ********************************* &groupingelements('Boxtext', '<Boxtext>*', 'shaded-box'); $t->change_gi('Boxtext','para'); # my @bitems = $t->get_xpath('//Boxtext'); # foreach $itm (@bitems) # { # # $itm->set_tag('shaded-box'); # $itm->insert('para'); # } # ********* SUBROUTINES *********** sub insertelements { (my $ft, my $it) = @_; my @Qt = $t->findnodes($ft); foreach my $qt (@Qt){$qt->insert($it);} } sub groupingelements { (my $ft,my $et,my $gt) = @_; my @Qt = $t->get_xpath("//$ft/.."); foreach my $qt (@Qt) { $qt->wrap_children($et, $gt); $qt->strip_att('id'); } } sub stags { (my $r,my $pt,my $xt) = @_; my @heads= $r->children($pt); foreach my $head (@heads) { my $headtext= $head->wrap_in($xt); my $more_text = $headtext->next_sibling; while($more_text && ($more_text->tag ne $pt)) { $more_text->move(last_child => $headtext); $more_text = $headtext->next_sibling; } } } # *********************************** $content = $t->sprint; $content =~s/@#/\&#/gsi; open (FOUT, ">$ARGV[1]") || die "can't open output file"; print FOUT $content;
Thanks,
Sivaraman
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Twig - src code working but executable not working
by GrandFather (Saint) on Jun 18, 2007 at 20:18 UTC | |
|
Re: XML::Twig - src code working but executable not working
by graff (Chancellor) on Jun 19, 2007 at 03:46 UTC | |
by aakikce (Acolyte) on Jun 19, 2007 at 04:59 UTC | |
by mirod (Canon) on Jun 19, 2007 at 06:12 UTC | |
by aakikce (Acolyte) on Jun 22, 2007 at 14:58 UTC |