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

In reply to Problem de-referencing a variable by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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.