Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2014-12-21 21:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (108 votes), past polls