in reply to Question of variable interpolation in regex

This line $boxLine =~ s/\.+/$string/o; uses the /o modifier, so the regular expression is only compiled once. That is, even if the value of $string changes, the regular expression won't reflect that. So the first time through, it compiles as s/\.+/    1/o and never changes again.

updated: Apparently, I'm talking rubbish. Sorry!

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re: Re: Question of variable interpolation in regex
by thelenm (Vicar) on Nov 15, 2002 at 16:56 UTC
    Actually, the left-hand side of the substitution (the regex) is the part that is only compiled once. The right-hand side will change as $string changes. Try this:
    my $foo = 'a'; for my $string ('b'..'z') { $foo =~ s/./$string/o; print "$foo\n"; }

    -- Mike

    --
    just,my${.02}