in reply to sorting difficulty
use strict; use warnings; my $str = q{<tag refid="5,8,7,3,2,1">}; sub sort_and_reformat { my $s = shift; return join " ", sort split m/,/, $s; } $str =~ s/"([^"]*)"/'"' . sort_and_reformat($1) . '"'/eg; print $str, $/;
The regex isn't very selective about what it considers an attribute, so you might want to tweak that.
Update: You can use look-ahead and -behind to get rid of that ugly substitution body:
$str =~ s/(?<=")([^"]*)(?=")/sort_and_reformat($1)/eg;
If you want to be more specific about what to match, you can use something like this:
$str =~ s/(?<=<tag refid=")([^"]*)(?=")/sort_and_reformat($1)/eg;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sorting difficulty
by texuser74 (Monk) on May 07, 2008 at 10:22 UTC | |
by moritz (Cardinal) on May 07, 2008 at 10:26 UTC | |
by texuser74 (Monk) on May 07, 2008 at 10:31 UTC |