if (/[\x20]{5}\(base 16\)[\t]{2}/) { ... if ($_ =~ m/([\d]+\.[\d]+\.[\d]+\.[\d]+).*([\w]{4})\.([\w]{4})\.([\w +]{4})/i) {
Why put a character class inside a character class?
if (/\x20{5}\(base 16\)\t{2}/) { ... if ($_ =~ m/(\d+\.\d+\.\d+\.\d+).*(\w{4})\.(\w{4})\.(\w{4})/i) {
And why use the /i option on a pattern that contains NO literal alphabetic characters?
open(INPUT, $ARGV[0]) || die "Cannot do eet! $!"; # Takes the inp +ut file name on the command line and builds an array. while (<INPUT>) { # This is the ARP + Cache file created from a copy/paste of a routers push @data, "$_"; # show arp comm +and. } close(INPUT); for (@data) { # This section iterates over the ARP cache array and + pulls the IP and MAC address out and stores it into a hash if ($_ =~ m/([\d]+\.[\d]+\.[\d]+\.[\d]+).*([\w]{4})\.([\w]{4})\.([\w +]{4})/i) { # Key is MAC my $temp = $2.$3.$4; + # Value is IP $hash{$temp} = $1; } }
What is the point of @data? Why not just populate %hash from inside the while loop? And why copy $_ to a string before pushing it into @data?
In reply to Re: Regex matching part of one hash key to another
by jwkrahn
in thread Regex matching part of one hash key to another
by KevinNC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |