Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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
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 meditating upon the Monastery: (7)
As of 2014-12-29 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (187 votes), past polls