### Re: Problem de-referencing a variable

by Not_a_Number (Prior)
 on Feb 09, 2009 at 21:49 UTC ( #742596=note: print w/replies, xml ) Need Help??

in reply to Problem de-referencing a variable

I think you might have an XY Problem here.

Correct me if I'm wrong, but I think that what you really want to do is to munge this input:

```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

using your %translation hash, to produce this output:

```Odp-
kIr+

This implies that each 20-character-long line in your input file may be divided into four segments, of respectively 6 + 6 + 6 + 2 bytes (counting from left to right).

In which case, why not simplify matter by stringifying the 'segments' in question? Your %reverse_translation could then look like this:

```(
110011 => 'I',
111101 => 'u',
11 => '*',
01 => '/',
... etc ...,
)

Here's a possible implementation, which works at least with the (rather sparse) data you provide:

```my %translation = (
# as in OP
);

my %reverse_translation;
for ( keys %translation ) {
my \$bin = join '', @{ \$translation{\$_}} ;
\$reverse_translation{\$bin} = \$_;
}

while ( <DATA> ) {
my @segments = unpack 'A6A6A6A2', join '', split /,/;
print \$reverse_translation{\$_} for @segments;
print "\n";
}

__DATA__
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

Create A New User
Node Status?
node history
Node Type: note [id://742596]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-01-24 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How did you see in the new year?

Results (257 votes). Check out past polls.

Notices?