PERL PERL5 PORTERS 11 PERL 34168 UNPACK USING A STRING INSTEAD OF A NUMBER FOR H AND B
Date: 17 Feb 2005 13:17:36 -0000

Subject: [perl #34168] Unpack using a string instead of a number for H and B
From: perlbug-followup@no-spam (Joshua Isom)

# New Ticket Created by Joshua Isom # Please include the string: [perl #34168]
# in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=34168 >

When using unpack, it treats the argument as a string by default. For example:

foreach (0 .. 0xF) {
print +(unpack 'H*', $_), ' ';
}

Returns:

30 31 32 33 34 35 36 37 38 39 3130 3131 3132 3133 3134 3135

Although I would expect it to return:

00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
Now, if instead I were to use:

foreach ('0' .. '15') {
print +(unpack 'H*', $_), ' ';
}

I would expect the first example. Whether or not perl forces numbers to be unpacked as a string for H and B is not told. To get what I would consider the proper value would require using chr first, but to me it seems excessive to have that requirement.

Summary of my perl5 (revision 5 version 8 subversion 6) configuration:
Platform:
osname=darwin, osvers=6.8, archname=darwin-64int uname='darwin joshua-isoms-computer.local. 6.8 darwin kernel version 6.8: wed sep 10 15:20:55 pdt 2003; root:xnuxnu-344.49.obj~2release_ppc power macintosh powerpc '
config_args='-Duse64bitint'
hint=previous, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=define use64bitall=undef uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler:
cc='cc', ccflags ='-fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe',
optimize='-Os',
cppflags='-no-cpp-precomp -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe'
ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build 1493)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=87654321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=8, prototype=define Linker and Libraries:
ld='cc', ldflags ='-flat_namespace -L/usr/local/lib -L/sw/lib -I/sw/include'
libpth=/sw/lib /usr/lib /usr/local/lib libs=-lgdbm -ldb -ldl -lm -lc perllibs=-ldl -lm -lc libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags=' -flat_namespace -bundle -undefined suppress -L/usr/local/lib -L/sw/lib'

Characteristics of this binary (from libperl):
Compile-time options: USE_64_BIT_INT USE_LARGE_FILES Built under darwin Compiled at Feb 1 2005 23:20:51
%ENV:
PERL5LIB="/sw/lib/perl5"
@no-spam /sw/lib/perl5
/System/Library/Perl/darwin /System/Library/Perl /Library/Perl/darwin /Library/Perl /Library/Perl /Network/Library/Perl/darwin /Network/Library/Perl /Network/Library/Perl .