Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

regular expressions and substituting in variables.

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

Pug has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on regular expressions and substituting in variables.

Replies are listed 'Best First'.
Re: regular expressions and substituting in variables.
by Adam (Vicar) on Jan 23, 2001 at 02:18 UTC
    The way to quickly go through and replace NUM with a constant is:
    @s_dn = map { s/NUM/1/; $_ } @s_dn;
    But it sounds like you have some rule for wanting to determine what to replace NUM with.
    for( @s_dn ) { my $num = 1; # calculate the local num, somehow. s/NUM/$num/g; }
Re: regular expressions and substituting in variables.
by Pug (Monk) on Jan 23, 2001 at 02:22 UTC
    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"; }
      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?

      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?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found