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

    Show us the smallest chunk of input data that demonstrates the error. Hint: take some of your current input data and trim it until you can remove no more characters without the error going away.


    DWIM is Perl's answer to Gödel
Re: XML::Twig - src code working but executable not working
by graff (Chancellor) on Jun 19, 2007 at 03:46 UTC
    It shows errors like

    use of uninitiated value in pattern and also use of uninitiated value in scalar assignment.

    You didn't actually paste in the exact messages -- you should have. But your inexact quotations are "close enough" that I can see they are warnings rather than errors.

    So you get some output? And the output you get seems ok? Are you missing some output that was expected? If you don't get all the output that you expect, then it would be important to show us what the last error message was -- because that last one is probably a real error (not just a warning).

    I'm with GrandFather: show us enough sample data to demonstrate how the output is incomplete (in addition to generating the warning messages that you mentioned). Don't forget to make it clear what the intended output should be.

      Hello Monks,

      Thanks for your reply. My input and outputs are as:

      Inuput:

      <chapter head>Part &#8211; International</chapter head> <outline text>Meanings attached</outline text> <outline text>The complex nature of international employee recognition + and reward</outline text> <outline text>Strategic issues</outline text> <body text>The design and maintenance of an organisation's employee re +ward system represents &#8216;a critical.</body text> <body text>The claim begs the question.</body text> <a head>DEFINING 'EMPLOYEE REWARD'</a head> <body text>Located in a transnational include:</body text> <bullet list>relations between the strategic aims set by corporate man +agement for the multinational</bullet list> <bullet list>an appraisal of the relationship between corporate polici +es and practices for determining rewards dependent on the job, the pe +rson, and the performance of employees across a variety of locations, + segmented by geography or occupational category or other material fa +ctor</bullet list> <bullet list>an account of the 'human capital' perspective &#8211; the + implied or express needs and priorities of individuals and groups en +gaged to work for the organisation.</bullet list> <b head>Continuities and differences</b head> <body text>So, what is the same and what is different about internatio +nal reward and recognition strategy.</body text>

      Output from script:

      <chapter> <title>Part &#8211;International</title> <outline-box> <para>Meaningsattached</para> <para>The complex nature of international employee recognition and +reward</para> <para>Strategicissues</para> </outline-box> <para>The design and maintenance of an organisation's employee rewar +d system represents &#8216;acritical.</para> <para>The claim begs thequestion.</para> <section> <title>DEFINING 'EMPLOYEEREWARD'</title> <para>Located in a transnationalinclude:</para> <list type="bullet"> <item> <para>relations between the strategic aims set by corporate ma +nagement for themultinational</para> </item> <item> <para>an appraisal of the relationship between corporate polic +ies and practices for determining rewards dependent on the job, the p +erson, and the performance of employees across a variety of locations +, segmented by geography or occupational category or other materialfa +ctor</para> </item> <item> <para>an account of the 'human capital' perspective &#8211; th +e implied or express needs and priorities of individuals and groups e +ngaged to work for theorganisation.</para> </item> </list> <sub-section> <title>Continuities anddifferences</title> <para>So, what is the same and what is different about internati +onal reward and recognitionstrategy.</para> </sub-section> </section> </chapter>

      output from exe:

      <chapter> <title>Part &#8211;International</title> <para>Meaningsattached</para> <para>The complex nature of international employee recognition andre +ward</para> <para>Strategicissues</para> <para>The design and maintenance of an organisation's employee rewar +d system represents &#8216;acritical.</para> <para>The claim begs thequestion.</para> <section> <title>DEFINING 'EMPLOYEEREWARD'</title> <para>Located in a transnationalinclude:</para> <bulletlist>relations between the strategic aims set by corporate +management for themultinational</bulletlist> <bulletlist>an appraisal of the relationship between corporate pol +icies and practices for determining rewards dependent on the job, the + person, and the performance of employees across a variety of locatio +ns, segmented by geography or occupational category or other material +factor</bulletlist> <bulletlist>an account of the 'human capital' perspective &#8211; +the implied or express needs and priorities of individuals and groups + engaged to work for theorganisation.</bulletlist> <sub-section> <title>Continuities anddifferences</title> <para>So, what is the same and what is different about internati +onal reward and recognitionstrategy.</para> </sub-section> </section> </chapter>

      Please look in to the bullet list section

      thanks

      Aakikce

        In case the problem comes from some weird interaction between get_xpath and perlapp, try replacing all the calls to get_xpath( '//foo') by descendants( 'foo') (same with findnodes that you used at one point).