data67 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Complex Data structures and sorting
by Super Monkey (Beadle) on Apr 19, 2002 at 17:35 UTC
    It looks like a simple matter of creating and sorting hashes. If the volume of data is even somewhat large (5K+ records), use a database or you could run into memory problems. The straight forward approach I would take for small record sets would be to create a hash for each field you want to sort on, making that field the key and the value being another hash of all the data related to that key. You will end up with a lot of data duplication. The alternative is a bit more complex, creating one hash (keyed on SSN) containing hashes of all data. Then you would have to create some sort routines. Actually, this would not be too difficult if the sample data is anything like the real stuff.
Re: Complex Data structures and sorting
by Super Monkey (Beadle) on Apr 19, 2002 at 21:05 UTC
    Here is an example that might be helpful. There is no sorting during the hash traversal, but you should be able to pick out what you need with some simple sorts here and there.
    #!/usr/bin/perl use strict; my %students = (); $students{456234567} = { name => 'Bob Smith', major => 'Engineering', level => 'Graduate', classes => { COMP8769 => { teacher => 'Dr.Smith', time => 'MWF 10:00', grade => 'A' }, COMP7960 => { teacher => 'Dr.Smith', time => 'MWF 11:00', grade => 'B' }, COMP7100 => { teacher => 'Dr. Rose', time => 'MWF 1:00', grade => 'B' }, COMP7600 => { teacher => 'Dr. Gillian', time => 'MWF 9:00', grade => 'A' }}}; $students{852234567} = { name => 'Ivan Milla', major => 'Business', level => 'Undergrad', classes => { BUS4000 => { teacher => 'Dr. Rossa', time => 'M 2:00', grade => 'C' }}}; $students{123234567} = { name => 'Sergio Veara', major => 'Arts', level => 'Graduate' }; $students{987234567} = { name => 'Richard Thompson', major => 'Economics', level => 'Undergrad', classes => { ECON6900 => { teacher => 'Dr. Jones', time => 'W 9:00', grade => 'A' }}}; $students{963434567} = { name => 'Patrick Klivert', major => 'Economics', level => 'Graduate' }; $students{789234567} = { name => 'Janfranco Vialli', major => 'Engineering', level => 'Graduate', classes => { BUS4000 => { teacher => 'Dr. Rossa', time => 'M 2:00', grade => 'A' }}}; # this will display the values of the hash foreach my $key (sort keys %students) { print "\n$key\n"; foreach my $kee (keys %{ $students{$key} }) { print " $kee : "; if (ref($students{$key}{$kee}) eq 'HASH') { foreach my $kei (keys %{ $students{$key}{$kee} }) { print "\n $kei : "; foreach my $kea (keys %{ $students{$key}{$kee}{$kei} }) { print "\n $kea : $students{$key}{$kee}{$kei}{$kea}"; } } } else { print "$students{$key}{$kee}\n"; } } }