Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: $1 in variable regex replacement string

by tadman (Prior)
on Feb 14, 2003 at 03:26 UTC ( #235168=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: $1 in variable regex replacement string
in thread $1 in variable regex replacement string

I'm not sure why you're using a hash there when this should do the trick:
sub safeswitch { no strict 'refs'; my @P = map { $$_ } 0..@+; $_[0] =~ s/\$(\d+)/$P[$1]/g; $_[0]; }
As far as I can tell, you're only using %seen to count?

Replies are listed 'Best First'.
Re: Re: $1 in variable regex replacement string
by belden (Friar) on Feb 15, 2003 at 01:01 UTC
    Good point. I originally wrote it using a hash, then a few minutes later discovered almost the exact same thing when I followed jsprat's link in this node. I thought about updating my code, but then decided it was buried so deep nobody would find it anyway ;)

    setenv EXINIT 'set noai ts=2'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://235168]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2018-03-17 19:29 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (225 votes). Check out past polls.