This will uc the first letter following < and </:
$string =~ s!(</?)([^/>])!$1.uc($2)!eg;
The key is the /e modifier on the regexp, which indicates that the right-hand side of the substitution regexp is Perl code which needs to be evaluated, rather than just a plain string.
Breaking it down into its components:
s! (</?) # Match and capture '<' followed by optional '/' ([^/>]) # Match and capture the next char, as long as # it's not a '>' or '/'. ! $1 # Replace with '<' or '</'. . uc($2) # Concatenate with the uc of $2. !egx
This approach is error-prone though. What if the literal text (not found inside a tag) has a '<' character int it? You don't have to write your own parser, when CPAN has many already written.
Updated: Fixed issue with '</' case.
Dave
In reply to Re: Ucfirst on xml elements
by davido
in thread Ucfirst on xml elements
by redhotpenguin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |