OK, here is a part of my ugly code (the better looking parts are borrowed from other proper codes). I use a pointer that travels along each line one word at a time and populates the hash. Hope someone shows me the right way to do it.

my @matches = split / /,$entry; my $position = 3; if ($matches[$position] eq "permit") { $hash{func} = $matches[$position]; $position++; } elsif ($matches[$position] eq "deny") { $hash{func} = $matches[$position]; $position++; } #completed action if ($matches[$position] eq "object-group") { $position++; my $protocol = get_obj_grp ($matches[$position]); #get_obj_grp + is a separate function read from a hash table $hash{protocol} = join('<br>',@{$protocol->{entries}}); $position++; } elsif($matches[$position] =~ /ip|tcp|udp|icmp/) { $hash{protocol} = $matches[$position]; $position++; } else { $position++; #shouldn't reach here }# completed protocol if ($matches[$position] eq "object-group") { $position++; my $source = get_obj_grp ($matches[$position]); $hash{source_net} = join('<br>',@{$source->{entries}}); $position++; } elsif ($matches[$position] eq "any") { $hash{source_net} = "any"; $position++; } elsif ($matches[$position] eq "host") { $position++; if ($matches[$position] =~ m/^\d+\.\d+\.\d+\.\d+$/) { $hash{source_net} = "host $matches[$position]"; } else{ $hash{source_net} = "host " . find_name($matches[$position +]); } $position++; } elsif($matches[$position] =~ m/^\d+\.\d+\.\d+\.\d+$/) { $hash{source_net} = $matches[$position]." ".$matches[$position ++1]; $position++; $position++; } elsif($matches[$position+1] =~ m/^\d+\.\d+\.\d+\.\d+$/) { $hash{source_net} = find_name($matches[$position])." ".$matche +s[$position+1]; $position++; $position++; } #completed source if ($matches[$position] eq "object-group") { $position++; my $source = get_obj_grp ($matches[$position]); $hash{dest_net} = join('<br>',@{$source->{entries}}); $position++; } elsif ($matches[$position] eq "any") { $hash{dest_net} = "any"; $position++; } elsif ($matches[$position] eq "host") { $position++; if ($matches[$position] =~ m/^\d+\.\d+\.\d+\.\d+$/) { $hash{dest_net} = "host $matches[$position]"; } else{ $hash{dest_net} = "host " . find_name($matches[$position]) +; } $position++; } elsif($matches[$position] =~ m/^\d+\.\d+\.\d+\.\d+$/) { $hash{dest_net} = $matches[$position]." ".$matches[$position+1 +]; $position++; $position++; } elsif($matches[$position+1] =~ m/^\d+\.\d+\.\d+\.\d+$/) { $hash{dest_net} = find_name($matches[$position])." ".$matches[ +$position+1]; $position++; $position++; } #completed destination if ($matches[$position] eq "object-group") { $position++; my $protocol = get_obj_grp ($matches[$position]); $hash{dest_port} = join('<br>',@{$protocol->{entries}}); $position++; } elsif($matches[$position] eq "eq") { $position++; $hash{dest_port} = $matches[$position]; } elsif($matches[$position] eq "range") { $position++; $hash{dest_port} = $matches[$position]." to ".$matches[$positi +on+1]; $position++; $position++; } else { $position++ }# completed port $entry = \%hash; }

In reply to Re: Regex to match a Cisco ACL by Anonymous Monk
in thread Regex to match a Cisco ACL by Anonymous Monk

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.