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:
This does the job fine, and the above example gets spat back out as: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) { }
<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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |