Here is my code I use to manipulate the list:Topology IPClassA subnet_address Topology IPClassA Device = 1 log_ratio Topology IPClassA Device = 1 Port = 1 poll_interval Topology IPClassC security_string Topology IPClassC Device = 2 Port = 2 poll_interval
This produces:use strict; # Global data structures use vars qw(@foo @bar); @bar = qw(Topology IPClassA subnet_address Topology IPClassA Device=1 log_ratio Topology IPClassA Device=1 Port=1 poll_interval To +pology IPClassC security_string Topology IPClassC Device=2 Port=2 poll_interval); my $i = 0; my $j = 1; print "Foo Before:\n\n"; foreach $_ (@bar){ print "$_\n";} push @foo, "Topology"; foreach $_ (@bar) { if ($bar[$i] eq $bar[$j]) { $i ++; $j ++; } else { push @foo, $bar[$j]; $i = 0; $j ++; } } print "\nFoo After:\n\n"; foreach $_ (@foo){ print "$_\n";}
What I would like to do is retain every unique path of Parent Nodes (ie nodes begining with a capital letter)between every "Topology" Entry, and If their is a difference insert Topology and its path into the List. Based on the input above I would like to see:Foo Before: Topology IPClassA subnet_address Topology IPClassA Device=1 log_ratio Topology IPClassA Device=1 Port=1 poll_interval Topology IPClassC security_string Topology IPClassC Device=2 Port=2 poll_interval Foo After: Topology IPClassA subnet_address Device=1 log_ratio Device=1 Port=1 poll_interval IPClassC security_string IPClassC Device=2 Port=2 poll_interval
Any ideas for an efficient data structure that would accomplish this?Foo After: Topology IPClassA subnet_address Device=1 log_ratio Port=1 poll_interval Topology IPClassC security_string Device=2 Port=2 poll_interval
In reply to Traversing an Hlist by The_Rev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |