in reply to Re^2: Differences in behavior in pack
in thread Differences in behavior in pack

Technically, it's possible to tell the difference

>perl -MDevel::Peek; -e"Dump(0x007102)" SV = IV(0x18265fc) at 0x2252f8 REFCNT = 1 FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK) IV = 28930 >perl -MDevel::Peek; -e"Dump(qq{\x30\x05\x15})" SV = PV(0x226680) at 0x225300 REFCNT = 1 FLAGS = (PADBUSY,PADTMP,POK,READONLY,pPOK) <-- Not IOK/UOK/NOK PV = 0x182f6a4 "0\5\25"\0 CUR = 3 LEN = 4

But checking for that would be extremely fragile. I strongly recommend against that approach. Instead, use some kind of meta data (a different command line switch, for example) to specify the format, then canonize it for internal use.

# Inputs my $input = "\x30\x05\x15"; my $packed = 1; # Canonize input if ($packed) { $input = unpack('N', substr(("\x00"x4).$input, -4)); } # Do some work #... # Output results printf("Results for 0x%X are %s\n", $input, "...");

Update: Added second snippet.