in reply to Re: Refactoring challenge.
in thread Refactoring challenge.
This seems like a rather problematic approach, in both before and after variants:
which I'd rather write as:my ($pos, $first ) = ( pos $string, $1 ) if $string =~ m/([\[\{\]\}, +])/g; return unless defined $pos;
$string =~ m/([\Q[]{},\E])/ or return; my($pos, $first) = ($+[0], $1);
With the code as is I'm not sure what you expect $pos and $first to be when the match fails, but if my reformulation is appropriate, it becomes clear that neither will ever be set to undef - that should either allow the remaining code to be simplified some, or point to a problem.
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Refactoring challenge.
by BrowserUk (Patriarch) on Mar 07, 2005 at 16:43 UTC | |
by Roy Johnson (Monsignor) on Mar 07, 2005 at 20:33 UTC |