1
% perl -Ilib -MDevel::Peek -le '$a="34567"; $a=~s/...//; Dump($a)' 
SV = PV(0x8171048) at 0x8186f48   # replaced "12345" with "34567"
  REFCNT = 1
  FLAGS = (POK,OOK,pPOK)
  OFFSET = 3
  PV = 0x8181bdb ( "34\003" . ) "67"\0
  CUR = 2
  LEN = 9

( "12\003" . )切碎部分中2的2 个零3从哪里来?

为什么我会在 chomped 部分得到这种输出( "34\003" . )

4

2 回答 2

2

A bug? "\003" is chr(3) in octal form. However:

$ perl -Ilib -MDevel::Peek -le '$a="12345"; $a=~s/...//; Dump($a)'
SV = PVIV(0x869b0bc) at 0x86a5060
  REFCNT = 1
  FLAGS = (POK,OOK,pPOK)
  IV = 3  (OFFSET)
  PV = 0x869fac3 ( "123" . ) "45"\0
  CUR = 2
  LEN = 5

I can't duplicate that; what version of perl are you using?

Note that the part of the string buffer in () is reserved but not currently in use.

于 2011-08-01T06:53:19.590 回答
1

我在 Windows 上使用 perl 5.12.2 得到与 sid_com 相同的结果。CUR但是无论如何,字符串长度都是从结构字段中获取的。我不明白为什么这应该是一个错误,其余的字符串缓冲区中可以有任何字节。

于 2011-08-01T08:12:50.537 回答