Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Problem de-referencing a variable

by Not_a_Number (Prior)
on Feb 09, 2009 at 21:49 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 20:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found