tommyw has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using undefined back-references?
by Abigail-II (Bishop) on Aug 19, 2002 at 16:10 UTC | |
|
Re: Using undefined back-references?
by Courage (Parson) on Aug 19, 2002 at 16:04 UTC | |
by tommyw (Hermit) on Aug 19, 2002 at 16:22 UTC | |
by fruiture (Curate) on Aug 19, 2002 at 16:31 UTC | |
|
Re: Using undefined back-references?
by mirod (Canon) on Aug 19, 2002 at 16:08 UTC | |
|
Re: Using undefined back-references?
by theorbtwo (Prior) on Aug 20, 2002 at 00:57 UTC |