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

Makes sense and that fixed my issue. Thanks! A little upset that I forgot substituting would reset my values... :'(
  • Comment on Re^2: Can anyone tell me what is going on with my code?(Regex match variables)

Replies are listed 'Best First'.
Re^3: Can anyone tell me what is going on with my code?(Regex match variables)
by AnomalousMonk (Archbishop) on Sep 30, 2015 at 19:55 UTC

    I find it's good practice to "capture" your capture variables immediately after a match even when you know for sure you will never be doing any further regex matching within that scope:

    if ($macs[1] =~ /(\S{17})\|(\S{17})/) { my ($mac1, $mac2) = ($1, $2); ... $mac1 =~ s/.../etc/g; $mac2 =~ s/as/needed/g; ... do_something_with($mac1, $mac2); ... }
    Just make this same, silly mistake as many times as I have and you'll never do otherwise!


    Give a man a fish:  <%-{-{-{-<

Re^3: Can anyone tell me what is going on with my code?(Regex match variables)
by mr_ron (Deacon) on Sep 30, 2015 at 19:30 UTC

    Just a thought. Since you are only switching one character you could use y/// or tr/// instead of s/// and you would not overwrite your match/capture variables. Like: tr/:/-/.

    Ron