Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Searching and printing complex data structures

by Cristoforo (Deacon)
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 t6.pl Company_A a,b,c Company_A b,g,c Company_B a,g,x


Comment on Re: Searching and printing complex data structures
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028025]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-08-30 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls