Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Help needed sorting data with multiple associated hashes

by tangent (Priest)
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

Replies are listed 'Best First'.
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?
[Corion]: ambrus: Hmm - I would assume that the onDestroy message is sent from the destructor and doesn't go through the messageloop, but maybe it is sent when a window gets destroyed but all components are still alive...
[ambrus]: Corion: partly deep source dive, partly just conservative coding even if it adds an overhead.
[Corion]: ambrus: Hmm - no, I haven't looked at wakeup intervals ... I wonder why it should want to wakeup periodically because it gets a lot of messages from the Windows message loop (on Windows obviously)
[ambrus]: (Alternately a deep source dive and then rewrite that event loop to make it better, and then as a bonus you get an idle method.)
[ambrus]: The 0.2 seconds wakeup is likely a workaround for some bug, but I can't guess what bug that is.
[ambrus]: It's been there since Prima 1.00 iirc
[Corion]: Hmmm... Weird. Maybe it needs that for doing its timers or something. Still weird.
[Corion]: But I guess I'll find out soonish, as my application seems to use Prima for more than just displaying the OpenGL output soonish ;))
[ambrus]: No, I think the timers are handled fine in the event loop, as far as I can see.
[Corion]: So far, I liked Prima quite well as it simply seems to do what I want even if it has an upside-down coordinate system. But it installs from CPAN out of the box and is cross-platform

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2016-12-09 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (150 votes). Check out past polls.