in reply to Re: Refactoring challenge.
in thread Refactoring challenge.

Maybe it would clearer like this, or at any rate more clear to people that only know perl. (I guess this is a vb/c thing.)
#$nesting++ if 1+index '[{', $char; #$nesting-- if 1+index ']}', $char; $nesting++ if $char=~/[[{]/; $nesting-- if $char=~/[\]}]/; # not sure if I escaped this right
The 1+index idiom baffled me, it requires that you know index returns -1 if no match. Thanks to demerphq for helping me understand.

Replies are listed 'Best First'.
Re^3: Refactoring challenge.
by BrowserUk (Patriarch) on Mar 08, 2005 at 17:31 UTC

    I was using regex in the earlier versions if you look back, but I personally find the escaped regexes to be most unreadable. I think that the way it is now captures the essence of the tests very well.

    In theory at least, you can use /[[}]/ without any escaping as (most) meta characters have no special meaning inside character classes, but it doesn't work in practice.

    I actually thought that was true for all meta characters until hv showed me /([\Q[]{},\E])/, which is better than the alternative, but still far from transparent.

    I've never used VB, though it's not totally dissimilar to the DEC Basic Plus I used 25 years ago. I still sometimes type instr when I mean index.

    (I think instr is the better name for the function actually)


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.