## PERL: How do i print an associative matrix?

PERL: How do i print an associative matrix?
# 1
09-27-2007
PERL: How do i print an associative matrix?

Hello guys,

I have in PERL an associative 2-dimensional array, called matrix. The array (actually the matrix) is made up like this
but the names a, b, c, d are set just at runtime.

The question is: how can i get all the keys of the matrix (i.e. a, b, c, d) and print the all matrix?

Thank you very much for your help!

Sergio
 foo.bar View Public Profile for foo.bar Find all posts by foo.bar
# 2
09-28-2007
What are a, b, c, d? Numbers or strings?

Assuming that is strictly 2-dimensional and all strings, that can be

For the keys, you can put a hash inside the loop and append each key each time one is retrieved. At the end, you simply iterate the hash to get back the keys.
 cbkihong View Public Profile for cbkihong Find all posts by cbkihong
# 3
09-28-2007
Yes they are strings. Thank you very much cbkihong!

The code you posted nearly works (there were some typing errors). I post the correct code:

Hope this will help sombody else.

Cheers,

Sergio
 foo.bar View Public Profile for foo.bar Find all posts by foo.bar

## How to print median values of matrix -awk?

I use the following script to print the sum and how could I extend this to print medians instead? thanks name s1 s2 s3 s4 g1 2 8 6 5 g1 5 7 9 9 g1 6 7 8 9 g2 8 8 8 8 g2 7 7 7 7 g2 10 10 10 10 g3 3 12 1 24 g3 5 5 24 48 g3 12 3 12 12 g3 2 3 3 3 output name s1 s2 s3 s4 g1 5 7 8 9...

## Randomization a matrix - perl / Shell

Hello all, I have a tricky question! (at least for me it is!). I'll try to explain it carefully here. Hope you can help me solving the whole or even parts of it! Here it is: I have a big input 0\1 table as a very simplified one is shown below: (The last row and column are the sum and...

## Perl- creating a matrix from a 3 column file

Dear all, I'm new in perl scripting and I'm trying to creating a matrix from a 3 column file sorting data in a particular manner. In the final matrix I need to have the first column "IDs" on the header of the columns and the second column values on the header of each row. And the value fo the...

## Matrix addition - Perl - PDL

Hi All, I have a question. I need to add 3 matrices of size 2000 x 2000. (i.e) 2000 rows and 2000 columns using Perl::PDL module. I used the following perl script #!/usr/bin/perl -w use strict; use warnings; use PDL; use PDL::Matrix; if ( @ARGV != 3 ) { die 'Two matrix files are...

## BASH: print matrix from single array

I am creating a report in groff and need to format data from a file into a table cell. Sample data: dador,173323,bpt,jsp,39030013338878,1 dador,173323,brew,jsp,39030013338860,1 dador,173323,brew,jsp,39030013339447,1 dador,173323,brew,jsp,39030013339538,1 I would like to build a table...

## Invert Matrix of Data - Perl

I have columnar data in arrays perl, Example - @a = (1,2,3); @array1 = (A,B,C); @array2 = (D,E,F); @array3 = (I,R,T); I want the data to be formatted and printed as 1 A D I 2 B E F 3 C F T and so on...

## Perl- matrix problem

A C G T - A 5 -4 -4 -4 -5 C -4 5 -4 -4 -5 G -4 -4 5 -4 -5 T -4 -4 -4 5 -5 - -5 -5 -5 -5 0 So lets say I have a matrix which looks something like (above). Its basically a scoring matrix. the numbers are...

## PERL: How do I get both sizes of a matrix?

Hi everybody, I have a matrix called @matrix dinamically built in PERL, so I don't know its exact sizes. It is a 2-dimensional matrix, so its elements are for example: \$matrix \$matrix \$matrix \$matrix \$matrix etc... I know i can get the number of the rows of the matrix with the...

## Perl: Sorting an associative array

Hi, When using sort on an associative array: foreach \$key (sort(keys(%opalfabet))){ \$value = \$opalfabet{\$key}; \$result .= \$value; } How does it handle double values? It seems to me that it removes them, is that true? If so, is there a way to get...