On Sat, Jul 7, 2012 at 9:07 AM, Chris Stinemetz <chrisstinem...@gmail.com> wrote: > Hello list, > > I have constructed an anonymous array with all the data I need. > I am having some difficulty in accessing and printing out the data the way > I want. > For the sake of not cluttering this thread too much I have uploaded the > anonymous array Data::Dumper output at github:gist > > https://gist.github.com/3066287 > > The output I am trying to achieve is simply printing out each index 0 for > each unique occurrence of index 1 (name1-6). > > For example: for name 5 in the anonymous array the output should be: > > 801 CDM 1, CCU 1, CE 3 2 > 812 CDM 1, CCU 1, CE 5 37 > 816 CDM 1, 2, CBR 3, 15MHz 12 > 817 CDM 1, 2, CBR 3, 15MHz 32 > 817 CDM 1, 2, CBR 1, 15MHz 4 > 831 CDM 1, 2, CBR 3, 15MHz 22 > 848 CDM 1, CCU 2, CE 1 8 > 873 CDM 1, CCU 1, CE 3 2 > 874 CDM 3, CCU 1, CE 5 18 > 886 ASMB 1 TXAMP 9 2 > > Cluster: Name5 > > _____________________________ > > 302 CDM 1, 2, CBR 1, 15MHz 2 > 317 CDM 1, 2, CBR 2, 15MHz 17 > 317 ASMB 1 TXAMP 6 15 > 340 TFU 1 4 > 371 CDM 1, 2, CBR 3, 15MHz 1 > 400 TFU 2 1 > 517 TFU 1 2 > 543 TFU 2 2 > > Cluster: Name6 > > > and print the rest of the instances just like the above. > > Sorry if this isn't clear let me know if there are any questions. > > Thanks in advance, > > Chris
Hello, Probably many ways to do this. Below is an example using a subset of the data you posted )chaning $VAR1 to $arrayRef): use warnings; use strict; my $arrayRef = [ [ '9 TFU 2 1 ', 'Name1', 71, 1, 9 ], [ '33 CDM 1, 2, CBR 2, 5MHz 2 ', 'Name2', 72, 1, 33 ], [ '38 CDM 1, 2, CBR 1, 15MHz 4 ', 'Name2', 72, 1, 38 ], [ '46 CDM 1, 2, CBR 2, 15MHz 1 ', 'Name1', 71, 1, 46 ], [ '58 CDM 1, 2, CBR 3, 15MHz 4 ', 'Name3', 71, 1, 58 ], [ '917 ASMB 1 TXAMP 9 4 ', 'Name4', 90, 1, 917 ], [ '917 CDM 1, 2, CBR 2, 15MHz 5 ', 'Name4', 90, 1, 917 ], [ '965 CDM 1, CCU 1, CE 5 1 ', 'Name4', 90, 1, 965 ] ]; my %hashByName; # Store all lines of interest by name foreach my $anotherArrayRef ( @$arrayRef ) { push @{$hashByName{$anotherArrayRef->[1]}}, $anotherArrayRef->[0]; } foreach my $name ( sort keys %hashByName ) { print "$name\n"; foreach my $value ( @{$hashByName{$name}} ) { # These lines appear to have a newline included print " $value"; } } HTH, Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/