Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

pack() v unpack() padding: bug or ???

by BrowserUk (Patriarch)
on Feb 16, 2015 at 13:44 UTC ( [id://1116868]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        a  A string with arbitrary binary data, will be null padded.
        A  A text (ASCII) string, will be space padded.
        Z  A null-terminated (ASCIZ) string, will be null padded.
    
  2. or download this
    print length pack '(A2)*', 'fr','ed','x';;
    6
    ...
    
    print unpack 'C*', pack '(Z2)*', 'fr','ed','x';;
    102 0 101 0 120 0  ## Note! the 'r' & 'd' characters have been thrown 
    +away? Another bug?
    
  3. or download this
    printf "'%s'\n", join"'", unpack '(A2)*', 'fredx';;
    'fr'ed'x'
    ...
    
    printf "'%s'\n", join"'", unpack '(Z2)*', 'fredx';;
    'fr'ed'x'
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1116868]
Approved by marto
Front-paged by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-16 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found