summaryrefslogtreecommitdiff
path: root/perl.man.3
diff options
context:
space:
mode:
Diffstat (limited to 'perl.man.3')
-rw-r--r--perl.man.326
1 files changed, 24 insertions, 2 deletions
diff --git a/perl.man.3 b/perl.man.3
index be1cc72e2b..d4574ebd69 100644
--- a/perl.man.3
+++ b/perl.man.3
@@ -1,7 +1,10 @@
''' Beginning of part 3
-''' $Header: perl_man.3,v 3.0.1.11 90/11/10 01:48:21 lwall Locked $
+''' $Header: perl_man.3,v 3.0.1.12 91/01/11 18:18:15 lwall Locked $
'''
''' $Log: perl.man.3,v $
+''' Revision 3.0.1.12 91/01/11 18:18:15 lwall
+''' patch42: added binary and hex pack/unpack options
+'''
''' Revision 3.0.1.11 90/11/10 01:48:21 lwall
''' patch38: random cleanup
''' patch38: documented tr///cds
@@ -291,17 +294,24 @@ of values, as follows:
X Back up a byte.
@ Null fill to absolute position.
u A uuencoded string.
+ b A bit string (ascending bit order, like vec()).
+ B A bit string (descending bit order).
+ h A hex string (low nybble first).
+ H A hex string (high nybble first).
.fi
Each letter may optionally be followed by a number which gives a repeat
count.
-With all types except "a" and "A" the pack function will gobble up that many values
+With all types except "a", "A", "b", "B", "h" and "H",
+the pack function will gobble up that many values
from the LIST.
A * for the repeat count means to use however many items are left.
The "a" and "A" types gobble just one value, but pack it as a string of length
count,
padding with nulls or spaces as necessary.
(When unpacking, "A" strips trailing spaces and nulls, but "a" does not.)
+Likewise, the "b" and "B" fields pack a string that many bits long.
+The "h" and "H" fields pack a string that many nybbles long.
Real numbers (floats and doubles) are in the native machine format
only; due to the multiplicity of floating formats around, and the lack
of a standard \*(L"network\*(R" representation, no facility for
@@ -342,6 +352,9 @@ Examples:
$foo = pack("i9pl", gmtime);
# a real struct tm (on my system anyway)
+ sub bintodec {
+ unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
+ }
.fi
The same template may generally also be used in the unpack function.
.Ip "pipe(READHANDLE,WRITEHANDLE)" 8 3
@@ -1358,6 +1371,15 @@ which will assume a bit vector operation is desired when both operands are
strings.
This interpretation is not enabled unless there is at least one vec() in
your program, to protect older programs.
+.Sp
+To transform a bit vector into a string or array of 0's and 1's, use these:
+.nf
+
+ $bits = unpack("b*", $vector);
+ @bits = split(//, unpack("b*", $vector));
+
+.fi
+If you know the exact length in bits, it can be used in place of the *.
.Ip "wait" 8 6
Waits for a child process to terminate and returns the pid of the deceased
process, or -1 if there are no child processes.