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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.