Allright, let's put it straight, I don't like to write other's code as I don't like others to write the code I'm in charge with. But, having said that, and having talk with qball in the CB, his problem was more interresting than it first sounded as he couldn't use a proper database to do the job (which obviously, would have been the best solution)

So, after having toyed with the idea of using DBD::RAM, it seemed that this very cool module wasn't able to fill the task (which I doubt, but I haven't tried to do it with it...)

So, here's my code:

#!/usr/bin/perl -w use strict; my $datas = {}; my %types; ##open needed files to use in program open(NAMES, "file1.csv") or die "Can't open NAMES file: $!\n"; open(TYPES, "file2.csv") or die "Can't open TYPES file: $!\n"; open(INFO, "file3.csv") or die "Can't open INFO file: $!\n"; # Process INFO while (<INFO>){ chomp; my ($unused_col, $type_name, $name_col) = split(/,/, $_, 3); $types{$type_name} = undef; # We never knows from this table where + # these fields are linked from? } close INFO; # Process NAMES while (<NAMES>){ chomp; my ($name_id, $c_name) = split(/,/, $_, 2); $datas->{$name_id} = {'c_name' => $c_name } # provided the id i +s unique } close NAMES; # Process TYPES while (<TYPES>){ chomp; my ($type_id, $name_id, $type_name) = split(/,/, $_, 3); push @{$datas->{$name_id}->{'type_name'}}, $type_name; # Not sure if we have to test the existence of the type. # Can't hurt too much (and avoid undesired autovivification?) $types{$type_name}++ if exists $types{$type_name}; } close TYPES; # Not seen output print "Not seen:\n"; foreach (keys %types){ print "$_\n" unless $types{$_} } # Names count print "Names total count:\n"; foreach (keys %{$datas}){ print $datas->{$_}->{'c_name'} . ": " . scalar(@{$datas->{$_}->{'type_name'}}) . "\n"; }

I guess there's a cleaner implementation of this. Mmmh, well I'll get back to DBD::RAM, I'm pretty sure it could do the job just fine...

Cheers,
-- Briac

<kbd>--
my $OeufMayo = new PerlMonger::Paris({http => 'paris.mongueurs.net'});</kbd>

In reply to Oh boy! A (mildly) complex data structure when there's no DB around by OeufMayo
in thread oh boy! by qball

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.