Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Problem de-referencing a variable

by Not_a_Number (Parson)
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
Comment on Re: Problem de-referencing a variable
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://742596]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2016-05-28 13:02 GMT
Find Nodes?
    Voting Booth?