I am trying to create an array of hashes. This is my code. $ 1, $ 2, etc. Match with regex and I checked that they exist.
Update: My original problem was fixed, but now I have a problem with my array not exceeding size 1 when I click on it with elements ...
Update 2: This is a scope issue, since @ACL needs to be declared outside the loop. Thanks everyone!
while (<>) {
chomp;
my @ACLs = ();
if($_ =~ /access-list\s+\d+\s+(deny|permit)\s+(ip|udp|tcp|icmp)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\s+eq (\d+))?/i){
my %rule = (
action => $1,
protocol => $2,
srcip => $3,
srcmask => $4,
destip => $5,
destmask => $6,
);
if($8){
$rule{"port"} = $8;
}
push @ACLs, \%rule;
print "Got an ACL rule. Current number of rules:" . @ACLs . "\n";
The hash array doesn't seem to get bigger.
source
share