On Tue, Aug 27, 2002 at 01:20:32PM +0200, Q wrote:
> Greetings.
> 
> Is there such a thing as mutlidimensional associative array ?
> 
> FILE 1 ( Filename = 23_59_54_20_08_2002)
> =====
> 
> FIELD1    FIELD2    FIELD3
> 20            40            60
> 
> 
> FILE 2 (Filename = 23_59_55_20_08_2002)
> =====
> 
> FIELD1    FIELD2    FIELD3
> 30            20            45

You already got an answer from Felix, but let me feed you a bit more
information as base-knowledge:

    perldoc perldsc

Read the "Perl Data Structures Cookbook".  There you'll find a nice
overview about the stuff you need.

    perldoc perlref
    
goes into far more detail, so take a look at that too.


You can take your approach and build a hash of hashes

    my $stuff = {
        '23_59_54_20_08_2002' => {
            field1      => 20,
            field2      => 40,
            field3      => 60,
        },
        '23_59_55_20_08_2002' => {
            field1      => 30,
            field2      => 20,
            field3      => 45,
        }
    }

    my $value = $stuff->{$fname}{field2};       # gives '40'

or you could create an array of hashes:

    my $stuff = [
        {
            filename    => '23_59_54_20_08_2002',
            data        => {
                field1 => ...
            }
        },
        {
            filename    => '23_59_55_20_08_2002',
            data        => {
                ...
            }
        }
    }

    my $value = $stuff->[0]{field2}             # gives '40'

For both methods, You could store the data in an array if the fieldnames
are of no interest to you:
    
    my $stuff = {
        '23_59_54_20_08_2002' => [ 20, 40, 60 ],
        ...
    ]

    my $value = $stuff->{23_59_54_20_08_2002}[2]        # guess what

and

    my $stuff = [
        {
            filename    => '23_59_54_20_08_2002',
            data        => [ 20, 40, 60 ],
        }, 
        ...
    ];

    my $value = $stuff->[0][1];                         # ditto

It all depends on what you want to do with the final data.  Do you want
to easily access single elements?  That would be a candidate for hashes.

Do you want to iterate over your data to calculate statistics?  Smells
like arrays...


And always remember:  When it comes to complex data structures,
Data::Dumper is your friend...


-- 
            Well, then let's give that Java-Wussie a beating... (me)

Michael Lamertz                        |     +49 2234 204947 / +49 171 6900 310
Sandstr. 122                           |                       [EMAIL PROTECTED]
50226 Frechen                          |                 http://www.lamertz.net
Germany                                |               http://www.perl-ronin.de 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to