Unfortunately, [the substitution] also removes any leading whitespace from the remainder of the string
Oops, I completely missed that. But adding a trailing
to $_consume() is enough to fix that.$_[0] =~ s/^\s+//;
Unfortunately, I cannot flatten the nesting in quite the way you have as the $pos ($length as you have it) will also be undefined if $first is undefined.
Both your original code and dragonchild's refactor contradict this - both use the returned $pos1 ($pos) unaltered when $first is undefined.
For now, the magic problem doesn't arise as $str is just a string (generated wholey within the outer layers of my code and will not have any magic attached)
As I remember it, the principle (and most embarrassing) time that it becomes a problem is when the parameter is tainted.
Hugo
In reply to Re^3: Refactoring challenge.
by hv
in thread Refactoring challenge.
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |