in reply to Ucfirst on xml elements
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Ucfirst on xml elements
by ambrus (Abbot) on Aug 29, 2004 at 17:57 UTC | |
|
Re^2: Ucfirst on xml elements
by redhotpenguin (Deacon) on Aug 29, 2004 at 16:45 UTC |