Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Searching and printing complex data structures

by Cristoforo (Curate)
on Apr 10, 2013 at 19:10 UTC ( #1028025=note: print w/replies, xml ) Need Help??

in reply to Searching and printing complex data structures

Using aitap's answer for finding the 'b's in Company_A, (I think the assignment to '()' isn't necessary), I reproduced your output with this code.
#!/usr/bin/perl use strict; use warnings; use 5.014; use Data::Dumper; my %hash = ( Company_A => { Identifier_1 => ['a', 'b'], Identifier_2 => ['b', 'g'], Identifier_3 => ['c'] }, Company_B => { Identifier_1 => ['a'], Identifier_2 => ['g'], Identifier_3 => ['x'] }); my $b_count = map { grep {$_ eq 'b'} @$_ } values %{ $hash{Company_A} +}; for my $company (sort keys %hash) { my (@ones, @multi); my $href = $hash{$company}; for my $id (sort keys %$href) { my $aref = $href->{$id}; if (1 == @$aref) { push @ones, $aref->[0]; } else { push @multi, $aref; } } if (@multi) { for my $m (@multi) { print "$company ", join(",", @$m, @ones), "\n"; } } else { print "$company ", join(",", @ones), "\n"; } }
C:\Old_Data\perlp>perl Company_A a,b,c Company_A b,g,c Company_B a,g,x

Replies are listed 'Best First'.
Re^2: Searching and printing complex data structures
by Anonymous Monk on Apr 10, 2013 at 19:17 UTC
    OP here. Thanks very much guys, I get the idea and will play around with the code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028025]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-04-22 22:17 GMT
Find Nodes?
    Voting Booth?