Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: bleach question

by Lotus1 (Vicar)
on Sep 29, 2014 at 14:38 UTC ( [id://1102360]=note: print w/replies, xml ) Need Help??


in reply to bleach question

Update: Thank you AnomalousMonk for pointing out how pack works and that the code in the OP does work. I tried it but somehow thought I was only seeing the original plaintext in the header when I saw #!/usr/bin/p and got distracted playing with Acme::Bleach.

roadtest: The code you provided is missing a step before the pack function. tr/ \t/01/; is needed to translate the spaces and tabs to 0's and 1's before pack can turn them into text. If you look at the brighten subroutine in Acme::Bleach you will see this step. The output from your example is shown below. I also had to add an empty line after the data so the heredoc could find the end.

#!/usr/bin/p

Replies are listed 'Best First'.
Re^2: bleach question
by AnomalousMonk (Archbishop) on Sep 29, 2014 at 16:14 UTC
    The code you provided is missing a step before the pack function. tr/ \t/01/; is needed to translate the spaces and tabs to 0's and 1's before pack can turn them into text.

    Not so. The 'b' and 'B' pack templates only look at the least-significant bit of a character to be packed, so space (0x20) and '0' (0x30) translate | pack to a 0 bit, and \t (0x09) and '1' (0x31) to a 1 bit.

    c:\@Work\Perl\monks>perl -wMstrict -le "for my $s (qq{\t \t \t \t }, '1000001001000010', 'qpppppqppqp +pppqp') { my $p = pack 'b*', $s; print qq{'$s' -> '$p'}; } " ' ' -> 'AB' '1000001001000010' -> 'AB' 'qpppppqppqppppqp' -> 'AB'

      Wow, interesting. Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 05:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found