Your split is going to return more than you expect. There will be 4 values returned by the split of your first line:
0 '' 1 project_id 2 12345 3 /project_id
Try:
($xmltag, $xmlvalue) = (split /\<|\>/, $string)[1,2];
The parentheses tell perl to treat the returned values from split as an array, and the subscripts pick out the elements you are specifically looking for.
I do the same thing in several of my programs using the following:
($tag,$value) = ($inline =~ /<(\/?\w+?)>([^<]*)/);
I'm using a regex to handle 3 cases I see in my input:
<tag>value</tag> or <tag> or </tag>
I can supply the details on how this works, but you might find it informative to try to figure out how it works yourself.
In reply to Re: Parsing an file that has xml like syntax
by GotToBTru
in thread Parsing an file that has xml like syntax
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |