in reply to Reusing camel code
split looks like a better choice than a regex. I whittled away at this and came up with the untested:
I'm fairly pleased with that, but might try to fit a pack in there. (How would you have used map?)for (split(/:/, $$pattern)) { # make sure it starts and ends with spaces $_ = 'S0' . $_ unless /^S/; $_ .= 'S0' unless /S\d+$/; my @pieces = split(/[SF](\d+)/, $_); while (my ($spaces, $fills) = splice(@pieces, 0, 2)) { $out .= " " x $spaces . substr($camel, $camelcount, $fills); } $out .= "\n"; }
Aside, this:
could be spelled:while (/(.)/g) { $camel .= $1 if $1 ne " "; }
I'm sure you can trim that down more, too. Don't forget to check out Acme::EyeDrops for a different take on things.tr/ //d; $camel .= $_;
Update, very shortly after: You could, of course, just split on [SF] and probably get the same effect, though you'll have an empty element at the start. It may or may not be more clear that way.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Reusing camel code
by gmax (Abbot) on Dec 03, 2001 at 15:19 UTC |
In Section
Seekers of Perl Wisdom