Perl is ideal. It cares not about numeric, string, memory allocation. Provided you can accept that it will burn perhaps as much as 4-10x more memory than optimised C it rocks. It is also very fast on this sort of task (often beating FAQ - Fair Average Quality - C).

Your description is a little distracted and does not really make explicit how you want to access the data. Making a few assumptions, perhaps this is close to what you want. I am using a hash, of array refs, which contain one or more hash refs to cope with you duplicate '?' thinging. ie in the struct there is a key '13' that contains an array ref. This array ref contains a series of hashes that contain the data pertaining to the '13' == ? thingy(s). Call it a link list. Literally < 10 minutes in Perl, hours in C/C++. It will be fast but it will burn memory. If you have the memory no worries. If not 1GB =~ 3 hours coding time in business case terms.

use Data::Dumper; my $struct; while(my $line = <DATA>){ chomp $line; next if $line =~ m/^\s*$/; my ( $key, $root, $parent, $current, $duration, $function) = pars +e_csv( $line ); push @{$struct->{$key}}, { root => $root, parent => $parent, current => $current, duration => $duration, function => $function, } } print Dumper $struct; # get all the 13 functions print "13 functions\n"; for my $ref( @{$struct->{13}} ) { print $ref->{function}, $/; } # this is a quick and dirty way to parse well formed CSV # use Test::CSV_XS if it is not well formed/trivial sub parse_csv { my ( $line ) = @_; $line =~ s/^\s*"|"\s*$//g; return split /"\s*,\s*"/, $line; } __DATA__ "1", "2", "3", "4", "100" , "A" "10", "20", "30", "40", "200" , "B" "11", "21", "31", "41", "300" , "C" "12", "22", "32", "42", "400" , "D" "13", "23", "33", "43", "500" , "E" "13", "23", "33", "53", "600" , "F" "13", "23", "33", "63", "700" , "G" "13", "23", "34", "73", "800" , "H" "13", "23", "34", "83", "900" , "I" "13", "24", "35", "93", "1000" , "J" "13", "24", "36", "103", "1100" , "K" __END__ $VAR1 = { '13' => [ { 'function' => 'E', 'parent' => '33', 'current' => '43', 'root' => '23', 'duration' => '500' }, { 'function' => 'F', 'parent' => '33', 'current' => '53', 'root' => '23', 'duration' => '600' }, { 'function' => 'G', 'parent' => '33', 'current' => '63', 'root' => '23', 'duration' => '700' }, { 'function' => 'H', 'parent' => '34', 'current' => '73', 'root' => '23', 'duration' => '800' }, { 'function' => 'I', 'parent' => '34', 'current' => '83', 'root' => '23', 'duration' => '900' }, { 'function' => 'J', 'parent' => '35', 'current' => '93', 'root' => '24', 'duration' => '1000' }, { 'function' => 'K', 'parent' => '36', 'current' => '103', 'root' => '24', 'duration' => '1100' } ], '1' => [ { 'function' => 'A', 'parent' => '3', 'current' => '4', 'root' => '2', 'duration' => '100' } ], '10' => [ { 'function' => 'B', 'parent' => '30', 'current' => '40', 'root' => '20', 'duration' => '200' } ], '11' => [ { 'function' => 'C', 'parent' => '31', 'current' => '41', 'root' => '21', 'duration' => '300' } ], '12' => [ { 'function' => 'D', 'parent' => '32', 'current' => '42', 'root' => '22', 'duration' => '400' } ] }; 13 Functions E F G H I J K

cheers

tachyon


In reply to Re: Hashes by tachyon
in thread Hashes by flemi_p

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.