Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Searching and printing complex data structures

by Cristoforo (Curate)
on Apr 10, 2013 at 19:10 UTC ( [id://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

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-25 14:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found