Reverred Monks,
I have the following problem I do not know how to solve. Maybe it's just a syntax issue, but I can't figure it out.
I need to interpret the output from a application that consists in a list of vectors with 20 numbers each. I know how to interpret this because originally, I had to code similar input to feed to the application in the first place. A partial table is given below as a hash of arrays (normally it would be in an external file I would read in with "do 'myfile.txt'"). I can reverse a hash all right - I found the perl function for that. But when I do, the keys of the new hash are now arrays. Perl knows that all right - if I print the keys, it prints something like:
ARRAY(0x33b930)
ARRAY(0x889eb0)
ARRAY(0x8896b4)
ARRAY(0x33b810)
So how do I now get access to what those arrays actually contain? E.g., how do I get:
[ 1, 1, 1, 0, 1, 1, ],
[ 1, 1, 1, 1, 0, 1, ],
[ 1, 1, 0, 0, 0, 0, ],
[ 0, 0, 1, 1, 1, 1, ],
Whenever I try, perl says the following:
Can't use string ("ARRAY(0x81e4c4)") as an ARRAY ref while "strict refs" in use at ./beispiel.plx line 36.
Any ideas? Am I going to have to try a completely different approach or is there a syntax for this?
#!/usr/bin/perl
# Input: A file containing vectors of 20 numbers, like:
# 1,1,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0
# 0,0,1,1,0,0,1,1,0,0,1,1,0,1,0,1,0,1,1,0
# Desired Output (see translation table below)
# Odp-
# kIr+
use strict;
use warnings;
my %translation = (
"i" => [ 1, 1, 1, 1, 1, 1, ],
"I" => [ 1, 1, 0, 0, 1, 1, ],
"o" => [ 1, 1, 1, 0, 1, 1, ],
"u" => [ 1, 1, 1, 1, 0, 1, ],
"O" => [ 1, 1, 0, 0, 0, 0, ],
"p" => [ 0, 0, 1, 1, 1, 1, ],
"d" => [ 0, 1, 1, 1, 1, 0, ],
"k" => [ 0, 0, 1, 1, 0, 0, ],
"f" => [ 0, 0, 1, 0, 1, 1, ],
"s" => [ 0, 0, 1, 0, 0, 1, ],
"r" => [ 0, 1, 0, 1, 0, 1, ],
"/" => [ 0, 1, ],
"+" => [ 1, 0, ],
"*" => [ 1, 1, ],
"-" => [ 0, 0, ],
);
my %reverse_translation = reverse %translation;
foreach my $key (keys %reverse_translation) {
print STDERR $key . "\n";
# my @array = @{ $key };
# print join ",", @array;
# print "\n";
}