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

Re: regular expressions and substituting in variables.

by Pug (Monk)
on Jan 23, 2001 at 02:22 UTC ( [id://53596]=note: print w/replies, xml ) Need Help??


in reply to regular expressions and substituting in variables.

Sorry about that Fellow Monks. here is version 1.1 *grin* I have a template that gives hints on how to setup (and how many) a Certificate Authority (or CA for short) . One of the things is if more then 1 CA is going to be made out of this template then how is the name of the CA going to change. The easiest thing is to just add a number at a User defined spot. so..
_ @s_dn=("c=US,ou=NUM,cn=foo", "c=DE,ou=NUM,cn=foo"); @dn=@s_dn; my $number=0; for(my $i=0; $i<3; $i++,$number++) { for(@dn) { s/NUM/$number/g} # now I would save this dn and other stuff now. print @dn; print "\tou= should be $number\n"; }

Replies are listed 'Best First'.
Re: Re: regular expressions and substituting in variables.
by Fastolfe (Vicar) on Jan 23, 2001 at 02:26 UTC
    Your outer for loop is doing nothing of any consequence. Your inner for loop is substituting all occurrences of NUM in @dn, leaving no occurrences left for your subsequent iterations of your outer loop.

    Perhaps you need to re-investigate your logic?

Re: Re: regular expressions and substituting in variables.
by chipmunk (Parson) on Jan 23, 2001 at 02:26 UTC
    The line @dn=@s_dn; should moved to just inside the first for loop, so that the original template is restored each time before you do the substitution. Otherwise, as you probably found, no substitutions will occur after the first iteration.
      Thanks that pointed showed 2 things I'm doing wrong. 1) the restoring. when I put that back I had the same issue on my script but not on the snipit given here the difference is I'm using a reference to an array in the script and so I'm not doing a copy I'm doing a ?pointer? is there anyway to stop that?
        It sounds like you want to do a deep copy, which you can find out about in Creating a copy of an array.

        If your data structure is just one array deep, though, this should be sufficient: $dn = [ @$s_dn ]; which creates a new array with the contents of the array referred to by $dn_sn.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found