The_Rev has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unique Array Data
by dws (Chancellor) on Mar 07, 2002 at 04:27 UTC | |
by The_Rev (Acolyte) on Mar 07, 2002 at 04:40 UTC | |
by dws (Chancellor) on Mar 07, 2002 at 05:07 UTC | |
by Anonymous Monk on Mar 07, 2002 at 11:53 UTC | |
by The_Rev (Acolyte) on Mar 07, 2002 at 12:28 UTC | |
by The_Rev (Acolyte) on Mar 07, 2002 at 04:49 UTC |