Okay. . . .I've looked through your previous nodes on this and here (as far as I understand it) is your solution, in pieces.

What you have is a hash with a comma delimited set of values. I'm going to assume you are stuck with this structure. In the *.PIN line, a variable (as you call it) seems to be in the whitepace, name, colon, value format. You want to change the letter appended after the colon on anything inside these comma seperated list, and make this change based on which hash entry these are in. We'll use a regular expression for this.

#Assuming that $variable contains the value to match for #( Something from $runset{GROUND-NODE} ) . . . $line =~ s/ #The substitution operator $variable #vssa, vss, etc . . . : #a colon . #any character (I, O, etc) / #substituted by . . . $variable #as before : #as before G #the G because it's in GROUND-NODE /xg; #Substitute globally

Make sure you understand regexes! If you don't then a simple one will throw you, and that is the solution you need here.

So, now that we has the regex, we just do a couple of iterations, and you are set.

#Complete code! #(Almost . . .) # @lines contains the *PIN lines . . . foreach $PIN (@lines) { foreach $ground_var (split /,/, $runset{GROUND-NODE}) { $PIN =~ s/$ground_var:./$ground_var:G/g; } foreach $power_var (split /,/, $runset{POWER-NODE}) { $PIN =~ s/$power_var:./$power_var:P/g }

Now, if you need explanations, ask and I'll give 'em :-).

Cheers,
Erik

In reply to Re: Simple replacement - only if they exist.. by erikharrison
in thread Simple replacement - only if they exist.. by Rhodium

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.