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

I'm looking for a data-structure with these attributes: Anyone seen anything like this go by? It is sort of a datacube in perl. Thanks in advance for any ideas.

Replies are listed 'Best First'.
Re: Data cube in Perl?
by t0mas (Priest) on Sep 20, 2000 at 16:18 UTC
    Have a look at PDL (pdl.perl.org).
    It is very useful for handling multidimensional data. Don't think it has the interface you need, but I think you should check it out before you go writing anything this complex yourself.

    /brother t0mas
      A great idea -- PDL would simplify the math, and I could wrap an object around it for the interface.

      I'm on a WinNT system and haven't compiled my own perl, or any of my own modules. PDL requires compiled C beneath. No PDL modules at Activestate. Suggestions? Is there a pure-Perl PDL (much slower, I'd suspect)? If I must compile the PDL C engine (ugh), will that work with the precompiled ActiveState binaries? (Ugh again.)

      Suggestions welcome! Thanks.

      Update found Win32 stuff at pdl.perl.org. Hurrah!
Re: Data cube in Perl?
by japhy (Canon) on Sep 20, 2000 at 16:32 UTC
    Well, I'm not sure I understand the normalization and the reduction (since you didn't show how a new reduced cube would look), but here's a start. You just need an object, really, with a couple methods and all.

    You have one to set the field names, one to set the valid field values (or have callbacks -- references to functions -- test the validity a value), and a couple to get data, or transform it, or reduce it.

    I was about to give you code, but I'd need to know much more about data cubes first. Sounds like you do. I doubt there's a data cube module in existence. Go for it.

    $_="goto+F.print+chop;\n=yhpaj";F1:eval
Data cube == hofhofhof.. ?
by gryng (Hermit) on Sep 20, 2000 at 18:24 UTC
    Hi nop!

    I think I agree with brother t0mas, use a module like PDL. Barring that, it seems that this sort of datacube is not very complex (for one you specify that you are required to specify all the arguements must be present unless specifically doing a reduction op).

    If this is truely the case I suggest just a nested hash. Why not? Just:

    my $dc = { 'north-america' => { '01/01/99' => { 'gross' => { 'we +b' => 99.99 'counter' => 10.95 } 'misc' => { 'web' => 2.50 } } { '01/02/99' => { 'gross' => '93.23' } } }
    With that you can just reference an item with: $dc->{'north-america'}{'01/01/99'}{'gross'}{'web'} If you want a reduction, you can pass the $dc reference to a procedure along with a list of fields such as:
    # supporting constants: my %fnum = { 'region' => 0, 'date' => 1, 'type' => 2, 'channel' => 3 } +; my $fsize = 4; sub reduce { my ($dc,$f) = @_; # sort fields to keep in decending order my @keep = reverse sort map { $fnum{$_} } @$f; for $cnt ($fsize-1 .. 0) { # hard code goes here! lol } }
    Sorry I'm chickening out writing that -- I just realized I'm late -- I have to drive to Montgomery. I'll rely on my brethren to fill in the blanks :) .

    One last thing, this is very easily bordering on "hairy" as a procedural program, I would suggest implementing the hash of hash's as an object so that you can get rid of these constants and make the whole thing more flexible and transparent. Good luck!

    Cheers,
    Gryn

Re: Data cube in Perl?
by princepawn (Parson) on Sep 20, 2000 at 18:39 UTC
    Something tells me you have a background in the languages Lucid and Field (intensional programming languages).

    Anyway, reforming, navigation, definition and querying of nested variable-type Perl structures can be done by the CPAN module Data::DRef.

    Navigation,definition and querying (more complex than DRef) can be done by the CPAN module Stone, which is a part of Boulder, all written by Lincoln Stein (author ID: LDS)

    Both products provides means of iterating over the entire data structure and performing operations on the retrieved results.

Re: Data cube in Perl?
by nop (Hermit) on Oct 01, 2000 at 21:16 UTC
    I put up some basic code along these lines here: Data cube.
    Turned out going the PDL route didn't offer much -- wasn't
    a math issue as much as a data access issue -- so I followed the
    suggestions of japhy and gryng and built a module.
    It is slow, but it did the trick for me.
    nop