#Parse the Netscreen configuration open (NETSCREEN, ") { chomp $line; if ($line =~ m/set\sservice\s(\".+\").?/) { my $serv = $1; print "Service name: $serv\n"; if (&check_stack($serv)) { print "It's on stack, keep compiling\n"; } else { print "Popping stack: @stack. Adding to stack: $1\n"; pop(@stack); push(@stack, $1); } } #print "$line\n"; } close (NETSCREEN); ################################################################################### # Subfunctions ################################################################################### #Checks the last element on the stack. Netscreen services are piled into multiple lines so we #need to keep track of the last entry. #Return TRUE if the last item is on the stack sub check_stack { my $stack = $_[0]; if (grep(/^$stack$/, @stack)) { return 1; } else { return 0; } }