in reply to Regexp: not what I'd expected

Had you run with warnings on (perl -w), perl would have given you a better clue about its interpretation. You would have seen that perl thinks $bef[$mid] is an element of an array.

Knowing that, I think your results will now make perfect sense to you. Since $bef[$mid] is not defined, $bef[$mid]$aft becomes a string containing undef followed by 'after.' $bef$mid[$aft] becomes 'before' followed undef.

Escape the square brackets with a backslash, and all will be well.

I think this was mainly just an oversight. One of those things that, until it's pointed out to you, you can't see it at all, but once you see it, it's obvious. :-)

Russ

Replies are listed 'Best First'.
RE: RE: Regexp: not what I'd expected
by greenhorn (Sexton) on Jul 04, 2000 at 06:13 UTC

    You're right that it's an oversight. I didn't spot $bef[$mid] as an element of an array. For shame.

    Perl--this'd be ActivePerl--had an interesting response to this script when the syntax was checked with '-w': it insisted that a right bracket was missing at line 24. Hmm. The version of the test that I'm running at the moment contains only 14 lines, of which the latter 7 are commented out.