I have the following data from a file, list.txt, where each element in the list has a non-numerical value associated with it, like so:
A X B Y C Z D X E X
I want to create a matrix where if any pair of elements have the value X (XX, XY, XZ) the code assigns 0 to that spot in the matrix, or otherwise it assigns 2 to it.
I realize I need to set arrays first, so I started with this (NB: code is incomplete, so don't expect it to run):
use strict; use warnings; open(IN, "list.txt") or die; chomp($line = <IN>); ($a, @ss) = split /\s+/, $line; while (chomp($line = <IN>)) { ($aa, @prs) = split /\s+/, $line; for ($i=0; $i<@prs; $i++) { $s{$aa}{$ss[$i]} = $prs[$i]; } } close(IN);
But I would appreciate any input on 1) code correctness, and 2)assigning numerical values to non-numerical pairs.
The expected output is a matrix with 0s and 2s, like so
A B C D A 0 0 0 0 B 0 2 2 0 C 0 2 2 0
In reply to matrices and non-numerical values by thschhk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |