Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

How do I use/reference Multidimensional hashed arrays?

by Anonymous Monk
on Jan 11, 2000 at 23:24 UTC ( #1970=categorized question: print w/replies, xml ) Need Help??
Contributed by Anonymous Monk on Jan 11, 2000 at 23:24 UTC
Q&A  > hashes


Description:

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; }

Answer: How do I use/reference Multidimensional hashed arrays?
contributed by Crulx

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"; }
Answer: How do I use/reference Multidimensional hashed arrays?
contributed by codeacrobat

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"; }

Please (register and) log in if you wish to add an answer



  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [Discipulus]: thanks choroba i'll update my answer
    [Lady_Aleena]: Hello Discipulus, Corion, choroba, and marioroy...
    [Corion]: Hi Lady_Aleena!
    [Lady_Aleena]: marioroy, are you also writing a Meditation for this?
    choroba o/
    Discipulus adds tozzetti alle mandorle to the platter on the sideboard.
    Lady_Aleena was checking #cbstream and saw the big announcement.
    [marioroy]: Tie::IxHash can be shared. Also similar modules. I cannot wait to post a solution sharing Tie::File and iterating among workers.
    [marioroy]: Lady_Aleena Yes, will post something with all the new features. Parallel with few lines of code.
    [marioroy]: Yes, will do for PM. I love PM.

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (10)
    As of 2017-05-26 08:50 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?