Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: variables allowed inside iterative loops in regular expressions?

by Three (Pilgrim)
on Nov 06, 2002 at 19:24 UTC ( [id://210850]=note: print w/replies, xml ) Need Help??


in reply to variables allowed inside iterative loops in regular expressions?

You can do your substitusion this way with the following code.
$a = 2; $b = "-"; $base = "ABCABC"; $stemp = "\/" . "ABC" x $a . "\/"; $regxp = eval 'qr' . $stemp; $base =~ s/$regxp/$b/g;
This returns a -

I know this is a bit brute force but it does work. Hope this helps. Edit:Hey I went back and changed the $a $b to other varables and the regular way works. ex.
$base =~ s/[ABC]{$multi}/$replace/g;
Three

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found