I discovered one more wrinkle. I didn't think the label_y blocks at the top of the file were important, but it turns out they are. Remember the format of those is:

<label_y="somevalue"> <label_z>a value</label_z> <label_z>a value</label_z> <label_z>a value</label_z> <label_z>a value</label_z> </label_y>

What I need to do is this:

Discard all but the first (or last, doesn't matter) of these, so there is only one such block in the file. Or, discard all of them and create a replacement - it would not really matter, just so there is only one.

If keeping one of the original blocks, save "somevalue" from the first line in a variable such as $somevalue.

Then, lower in the program, before writing the "kept" label_a blocks to the output file, I need to do this:

$e->set_att( 'channel' => $somevalue );

Since what's been posted so far is far more elegant than anything I would have come up with, I'd be interested in knowing a good way to do discard all (or all but one) of those initial blocks, and insert a replacement if needed, so there is only one.

By the way, relative to my previous post I did discover keep_atts_order => 'TRUE', which works in Linux but for some reason not in ActivePerl in Windows.


In reply to Re^3: How can I keep or discard certain blocks of an XML file based on first line of block? by Anonymous Monk
in thread How can I keep or discard certain blocks of an XML file based on first line of block? by Anonymous Monk

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.