Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Keyed matrix

by aitap (Deacon)
on Sep 03, 2012 at 12:21 UTC ( #991414=note: print w/ replies, xml ) Need Help??


in reply to Keyed matrix

What do you mean by "matrix"? There is no object in Perl (at least in the core modules) called "matrix". See perldata.

What you actually need is a hash of arrays. Hashes can contain only (possibly blessed) scalar values, so you cannot just put arrays in the hash. Instead, need to create array references and put them in a hash. See perlreftut for more information on this. For example,

my %hash = ( one => [ 1, 2, 3, ], two => [ 4, 5, 6, 7, ], three => [ 8, ], ); print ((join "\t", (sort keys %hash)),"\n"); my $i = 0; my $defined; do { $defined = 0; map {$defined++ if defined $hash{$_}->[$i]} (keys %hash); for (sort keys %hash) { print $hash{$_}->[$i] // " ", "\t"; }; print "\n"; $i++; } while ($defined > 0); __END__ one three two 1 8 4 2 5 3 6 7

Sorry if my advice was wrong.


Comment on Re: Keyed matrix
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2014-09-18 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (111 votes), past polls