in reply to Can anyone tell me what is going on with my code?(Regex match variables)

What do you expect the values of $1 and $2 to be after this line:

s/:/-/g

You will need to copy the values before doing another regular expression match.

Replies are listed 'Best First'.
Re^2: Can anyone tell me what is going on with my code?(Regex match variables)
by samh785 (Initiate) on Sep 30, 2015 at 17:49 UTC
    If you look in the output I'm expecting all :'s to be replaced with -'s. This worked for $mac1 but not for $mac2. Not sure what you mean by I'll need to copy the value(especially when I didn't need to for the first variable?). Thanks for looking into this.
      $2 is undefined when you assign it to $mac2 because you ran another regex in between, and that regex cleared $2. Assign $2 to $mac2 before the substitution, and it will work OK.