The pack Function Character Codes : pack « System Functions « Perl

Perl
1. Array
2. CGI
3. Class
4. Data Type
5. Database
6. File
7. GUI
8. Hash
9. Language Basics
10. Network
11. Regular Expression
12. Report
13. Statement
14. String
15. Subroutine
16. System Functions
17. Win32
18. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Perl » System Functions » pack 
The pack Function Character Codes
     


Character Code           Meaning

a                        Convert to its ASCII character value; pad empty characters with null

A                        Convert to its ASCII character value; pad empty characters with spaces

b                        Convert to a bit string from low to high order bit

B                        Convert to a bit string from high to low order bit

c                        Convert to a signed character

C                        Convert to an unsigned character

d                        Convert to a double-precision (floating-point number in the native platform format)

f                        Convert to a single-precision (floating-point number in the native platform format)

h                        Convert a hex string, putting the lower order nibble first

H                        Convert a hex string to ASCII characters, putting the high order nibble first

i                        Convert to signed integer format

I                        Convert to unsigned integer format

l                        Convert to signed long format

L                        Convert to unsigned long format

n                        Convert to short big endian order

N                        Convert to long big endian order

p                        Convert a pointer to string format

P                        Convert a pointer to a fixed-length string

s                        Convert to signed short format

S                        Convert to unsigned short format

v                        Convert to short little endian format

V                        Convert to long little endian format

u                        Convert to uu encoded format

x                        Insert null byte

X                        Back up one byte

@                        Null fill to absolute position




#!/usr/local/bin/perl

$packed = pack "a10" "Test";

print "$packed Null Padded\n\n";

print "pad empty characters with spaces\n\n";

$packed = pack "A10" "Test";

print "$packed Space Padded\n\n";

$packed = pack "b32" "01000101010100100100100101000011";

print "$packed The right most bit is the most significant\n\n";

$packed = pack "B32" "01000101010100100100100101000011";

print "$packed The left most bit is the most significant\n\n";

$packed = pack "c4"0x450x520x490x43;

print "$packed Numbers (hex) to ASCII, unsigned\n\n";

$packed = pack "C4", , 10111410599;

print "$packed Numbers (decimal) to ASCII, signed\n\n";

$packed = pack "h8""11111111111";

print "$packed Hex low Nibble first to  ASCII\n\n";

$packed = pack "H8""1111111111";

print "$packed Hex High Nibble first to ASCII\n\n";

$packed = pack "d", , 101.134;

print "$packed Double Precision native format packed for shipment\n\n";

$packed = pack "f", , 101.134;

print "$packed Single Precision native format packed for shipment\n\n";

$packed = pack "i5", , "97","98","99","100","101";

print "$packed Unsigned Packed Integers\n\n";

$packed = pack "I5", , "97","98","99","100","101";

   
    
    
    
    
  
Related examples in the same category
1. print pack("c*", 68, 69, 70, 71);
2. print pack("c3", 65, 66, 67);
3. print pack("ccc", 88, 89, 90);
4. The pack-format characters, as used by unpack.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.