Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Question of variable interpolation in regex

by tommyw (Hermit)
on Nov 15, 2002 at 16:51 UTC ( [id://213200]=note: print w/replies, xml ) Need Help??


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}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://213200]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-20 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found