This is my first post here, I have a question about something I can't explain.
I'm pretty sure I know what I did wrong, I'm just not 100% sure why it was wrong and wanted to clarify to better my understanding of regex in perl, as I'm fairly inexperienced and looking to improve.
I was searching for vlan ids for removal in the output of "ip addr" in the following way.
my $ethernet=`ip addr`; if ($ethernet!~/eth1\.\d{4}\@/gm){ print "No vlans exist on device.\n"; exit; } while ($ethernet=~/(eth1\.\d{4})\@/gm) { print `ip link del $1\n"; print "Removed $1\n"; }
Doing this as above mostly worked, but it would always miss the first entry for no reason I can explain. So if there were 25 vlan entries in the string from 1001 to 1025 it would match and delete 1002-1025 without fail, and miss 1001 every time.
Changing line 2 to:
if ($ethernet!~/eth1\.\d{4}\@/){Does what I intended to do.
I had the same problem with a similar line I was using to scrub IP addresses off the vlan devices again missing the first match, I just don't understand why the while loop breaks in the way it does because of the /gm flag on the preceeding if statements match, and was hoping someone could explain. Thanks in advance.
In reply to A regex question. by FeistyLemur
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |