(F) The '!' is allowed in pack() and unpack() only after certain types.
See L<perlfunc/pack>.
-=item # cannot take a count
+=item / cannot take a count
(F) You had an unpack template indicating a counted-length string,
but you have also specified an explicit size for the string.
See L<perlfunc/pack>.
-=item # must be followed by a, A or Z
+=item / must be followed by a, A or Z
(F) You had an unpack template indicating a counted-length string,
which must be followed by one of the letters a, A or Z
to indicate what sort of string is to be unpacked.
See L<perlfunc/pack>.
-=item # must be followed by a*, A* or Z*
+=item / must be followed by a*, A* or Z*
(F) You had an pack template indicating a counted-length string,
Currently the only things that can have their length counted are a*, A* or Z*.
See L<perlfunc/pack>.
-=item # must follow a numeric type
+=item / must follow a numeric type
(F) You had an unpack template that contained a '#',
but this did not follow some numeric unpack specification.
=item *
-The C<"#"> character allows packing and unpacking of strings where the
+The C<"/"> character allows packing and unpacking of strings where the
packed structure contains a byte count followed by the string itself.
-You write I<length-item>C<#>I<string-item>.
+You write I<length-item>C</>I<string-item>.
The I<length-item> can be any C<pack> template letter,
and describes how the length value is packed.
For C<unpack> the length of the string is obtained from the I<length-item>,
but if you put in the '*' it will be ignored.
- unpack 'C#a', "\04Gurusamy"; gives 'Guru'
- unpack 'a3#A* A*', '007 Bond J '; gives (' Bond','J')
- pack 'n#a* w#a*','hello,','world'; gives "\000\006hello,\005world"
+ unpack 'C/a', "\04Gurusamy"; gives 'Guru'
+ unpack 'a3/A* A*', '007 Bond J '; gives (' Bond','J')
+ pack 'n/a* w/a*','hello,','world'; gives "\000\006hello,\005world"
The I<length-item> is not returned explicitly from C<unpack>.
C<pack> (and C<unpack>) handle their output and input as flat
sequences of bytes.
+=item *
+
+A comment in a TEMPLATE starts with C<#> and goes to the end of line.
+
=back
Examples:
#endif
if (isSPACE(datumtype))
continue;
+ if (datumtype == '#') {
+ while (pat < patend && *pat != '\n')
+ pat++;
+ continue;
+ }
if (*pat == '!') {
char *natstr = "sSiIlL";
DIE(aTHX_ "x outside of string");
s += len;
break;
- case '#':
+ case '/':
if (oldsp >= SP)
- DIE(aTHX_ "# must follow a numeric type");
+ DIE(aTHX_ "/ must follow a numeric type");
if (*pat != 'a' && *pat != 'A' && *pat != 'Z')
- DIE(aTHX_ "# must be followed by a, A or Z");
+ DIE(aTHX_ "/ must be followed by a, A or Z");
datumtype = *pat++;
if (*pat == '*')
pat++; /* ignore '*' for compatibility with pack */
if (isDIGIT(*pat))
- DIE(aTHX_ "# cannot take a count" );
+ DIE(aTHX_ "/ cannot take a count" );
len = POPi;
/* drop through */
case 'A':
#endif
if (isSPACE(datumtype))
continue;
+ if (datumtype == '#') {
+ while (pat < patend && *pat != '\n')
+ pat++;
+ continue;
+ }
if (*pat == '!') {
char *natstr = "sSiIlL";
}
else
len = 1;
- if (*pat == '#') {
+ if (*pat == '/') {
++pat;
if (*pat != 'a' && *pat != 'A' && *pat != 'Z' || pat[1] != '*')
- DIE(aTHX_ "# must be followed by a*, A* or Z*");
+ DIE(aTHX_ "/ must be followed by a*, A* or Z*");
lengthcode = sv_2mortal(newSViv(sv_len(items > 0
? *MARK : &PL_sv_no)));
}
require Config; import Config;
}
-print "1..148\n";
+print "1..152\n";
$format = "c2 x5 C C x s d i l a6";
# Need the expression in here to force ary[5] to be numeric. This avoids
print "not " unless pack("V", 0xdeadbeef) eq "\xef\xbe\xad\xde";
print "ok ", $test++, "\n";
-# 143..148: #
+# 143..148: /
my $z;
-eval { ($x) = unpack '#a*','hello' };
+eval { ($x) = unpack '/a*','hello' };
print 'not ' unless $@; print "ok $test\n"; $test++;
-eval { ($z,$x,$y) = unpack 'a3#A C#a* C#Z', "003ok \003yes\004z\000abc" };
+eval { ($z,$x,$y) = unpack 'a3/A C/a* C/Z', "003ok \003yes\004z\000abc" };
print $@ eq '' && $z eq 'ok' ? "ok $test\n" : "not ok $test\n"; $test++;
print $@ eq '' && $x eq 'yes' ? "ok $test\n" : "not ok $test\n"; $test++;
print $@ eq '' && $y eq 'z' ? "ok $test\n" : "not ok $test\n"; $test++;
-eval { ($x) = pack '#a*','hello' };
+eval { ($x) = pack '/a*','hello' };
print 'not ' unless $@; print "ok $test\n"; $test++;
-$z = pack 'n#a* w#A*','string','etc';
+$z = pack 'n/a* w/A*','string','etc';
print 'not ' unless $z eq "\000\006string\003etc"; print "ok $test\n"; $test++;
+# 149..152: / with #
+
+eval { ($z,$x,$y) = unpack <<EOU, "003ok \003yes\004z\000abc" };
+ a3/A # Count in ASCII
+ C/a* # Count in a C char
+ C/Z # Count in a C char but skip after \0
+EOU
+print $@ eq '' && $z eq 'ok' ? "ok $test\n" : "not ok $test\n"; $test++;
+print $@ eq '' && $x eq 'yes' ? "ok $test\n" : "not ok $test\n"; $test++;
+print $@ eq '' && $y eq 'z' ? "ok $test\n" : "not ok $test\n"; $test++;
+
+$z = pack <<EOP,'string','etc';
+ n/a* # Count as network short
+ w/A* # Count a BER integer
+EOP
+print 'not ' unless $z eq "\000\006string\003etc"; print "ok $test\n"; $test++;