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


In reply to XML::Twig - src code working but executable not working by aakikce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.