in reply to Why is it "While Regex"ing,...Things do NOT seem to work!
As Roy Johnson correctly said, your first regex matches the same lines, your third matches. This doesn't happen, if you anchor the regex with /^.../ for the start of the line.
I would also do it like this to not match the second regex,when it's not appropriate:
if (my $hit= /^port-channel (\d+)$/ .. /^\s*$/) { if ($hit == 1) { $pc_name = $1; next; } $Rec->{$pc_name}->{$1} = $2 if (m|(fc\d+/\d+)\s+\[(\w+)\]|); #line + 15 } elsif (my $hit= /^interface port-channel (\d+)$/ .. /^\s*$/) { if ($hit == 1){ $key = $1; next; } $hash->{$key}->{$1} = $2 if (/switchport description To (\w+) ([\d +\.]+)/); #line 18 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why is it "While Regex"ing,...Things do NOT seem to work!
by blackadder (Hermit) on Oct 10, 2005 at 18:23 UTC |