My objective is to retain any unique order after every Topology Entry. This is just an example, I actually have a lot more data I'm working with. This is my code:Foo Before: Topology IPClassA subnet_address=0 Topology IPClassA Device model_name=1 Topology IPClassB Device model_name=2
This is the output:use strict; # Global data structures use vars qw(@foo @bar); @bar = qw(Topology IPClassA subnet_address=0 Topology IPClassA Device model_name=1 Topology IPClassB Device model_name=2); 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";}
It works great except for the fact that I need to push Topology on the array just before IPClassB, because this isn't the same pattern as the previous path beggining with the root Topology. Does anyone have any suggestions. ThanksFoo After: Topology IPClassA subnet_address=0 Device model_name=1 IPClassB Device model_name=2
In reply to Unique Array Data by The_Rev
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |