Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 taking refuge in the Monastery: (12)
As of 2015-07-31 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls