I'm working on converting some pseudo-SGML we've got at work into XML. The first step is ensuring that it's well formed. We've got some tags which look like:

<e st="obs" st="ali" num="1">
which won't parse, since duplicate attributes aren't allowed.

So I'm converting them with the following code:

my $NMTEXT='[A-Za-z]\w*'; while (s/<([^>]*)\s+ # Open tag, name and assorted crud. ($NMTEXT)="([^ >]*)" # Attribute and value (\s+[^>]*)?\s+ # Optional assorted crud \2="([^ >]*)" # Repeated attribute and value /<$1 $2="$3,$5"$4/gx) { }
This does the job fine, and the above example gets spat back out as:
<e st="obs,ali" num="1">
But in the process, I get warned about:
Use of uninitialized value in concatenation (.) or string at mkdtd.pl line 33, <XT> line 1.
I've run it through the debugger and found that in this case, I'm getting: ($1, $2, $3, $4) = ('e', 'st', 'obs', undef, 'ali'). Yup, it's right: there's no optional assorted crud.

So my question is: what's the best way of dealing with this? I don't want to turn warnings off, in case anything else might slip past, but I don't want to have this complaint thrown at me all the time.

(As a side issue, I also feel guilty about using a while loop with no body. Any better suggestions?)

--
Tommy
Too stupid to live.
Too stubborn to die.


In reply to Using undefined back-references? by tommyw

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.