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

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?


Comment on Re: $1 in variable regex replacement string
Download Code
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 ;)

    blyman
    setenv EXINIT 'set noai ts=2'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (21)
As of 2015-07-28 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls