Skip to content

Commit 2d764b4

Browse files
committed
perlfunc/pack: fix pack @ example
- Fix the `@1A((@2A)@3a)` example to use single quotes, not double quotes (which would interpolate array variables). - Replace `pack L=>0x12345678` by the more obvious `pack("L", 0x12345678)` (we're not trying to obfuscate our example code (right?)). Fixes #22425.
1 parent 382176c commit 2d764b4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pod/perlfunc.pod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5790,7 +5790,7 @@ These are called mid-endian, middle-endian, mixed-endian, or just weird.
57905790

57915791
You can determine your system endianness with this incantation:
57925792

5793-
printf("%#02x ", $_) for unpack("W*", pack L=>0x12345678);
5793+
printf("%#02x ", $_) for unpack("W*", pack("L", 0x12345678));
57945794

57955795
The byteorder on the platform where Perl was built is also available
57965796
via L<Config>:
@@ -5935,7 +5935,9 @@ L<C<unpack>|/unpack TEMPLATE,EXPR>, also via the C</>
59355935
template character. Within each repetition of a group, positioning with
59365936
C<@> starts over at 0. Therefore, the result of
59375937

5938-
pack("@1A((@2A)@3A)", qw[X Y Z])
5938+
# note: single quotes around the template string to prevent
5939+
# array interpolation of @1, @2, @3
5940+
pack('@1A((@2A)@3A)', qw[X Y Z])
59395941

59405942
is the string C<"\0X\0\0YZ">.
59415943

0 commit comments

Comments
 (0)