Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Help needed sorting data with multiple associated hashes

by tangent (Deacon)
on Feb 26, 2013 at 01:47 UTC ( #1020595=note: print w/ replies, xml ) Need Help??


in reply to Help needed sorting data with multiple associated hashes

One way to do it is to create another hash to map the parts to the key:

my %table; my %map; foreach my $key (sort keys %Data) { my $lValue = $Data{$key}; my @array = split ' ', $lValue; my $lPartStart = $array[2]; my $lPartEnd = $array[4]; my $lReference = $array[8]; chop($lReference); $table{$lReference} = [] unless exists $table{$lReference}; push @{$table{$lReference}}, $lPartStart; $map{$lReference}{$lPartStart} = $key; # THIS LINE ADDED } foreach my $lReference (sort keys %table) { print "Ref: $lReference, parts: "; my @parts = @{$table{$lReference}}; print join ', ', sort @parts; print "\n"; } foreach my $lReference (sort keys %table) { print "Ref: $lReference, lines: "; my @parts = @{$table{$lReference}}; my @lines = map { $map{$lReference}{$_} } sort @parts; print join ', ', @lines; print "\n"; }
Output:
Ref: 1, parts: 1, 2, 3 Ref: 2, parts: 2, 3, 4 Ref: 1, lines: 5, 4, 6 Ref: 2, lines: 17, 18, 16


Comment on Re: Help needed sorting data with multiple associated hashes
Select or Download Code
Re^2: Help needed sorting data with multiple associated hashes
by willk1980 (Novice) on Feb 27, 2013 at 17:15 UTC
    Thanks that got me started :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (15)
As of 2014-07-24 13:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls