Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

How do I use/reference Multidimensional hashed arrays?

by Anonymous Monk
on Jan 11, 2000 at 23:24 UTC ( #1970=perlquestion: print w/replies, xml ) Need Help??

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

I want a more efficient way of referencing and loading data into an array without using multiple array variables(a,b,c etc..) Is that called a multidimensional array?
while($num<10) { $num++; $data1="some random data from source 1"; $data2="some random data from source 1"; $data3="some random data from source 1"; $a($num)=$data1; $b($num)=$data2; $c($num)=$data3; }

Replies are listed 'Best First'.
Re: How do I use/reference Multidimensional hashed arrays?
by Crulx (Monk) on Jan 21, 2000 at 04:38 UTC
    Here is how you create and use a multidimensional hash that contains arrays.
    my $data_source = {}; for( my $i = 0; $i < 10; $i++) { $data_source->{a}[$i] = "source a's data"; $data_source->{b}[$i] = "source b's data"; $data_source->{c}[$i] = "source c's data"; }
Re: How do I use/reference Multidimensional hashed arrays?
by codeacrobat (Chaplain) on Mar 26, 2006 at 10:57 UTC
    push, pop, splice, shift, unshifting is a bit ugly, but works too.
    my $data_source = {}; for( my $i = 0; $i < 10; $i++) { push @{$data_source->{a}}, "source a's data"; push @{$data_source->{b}}, "source b's data"; push @{$data_source->{c}}, "source c's data"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1970]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2022-12-05 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?