develooper Front page | perl.perl5.porters | Postings from September 2010

Why do we parse v-strings this way?

Thread Next
From:
David Golden
Date:
September 26, 2010 13:10
Subject:
Why do we parse v-strings this way?
Message ID:
AANLkTinXfTvNm-EvppmOghs4iHg+59AGRkBwO9RbCP_u@mail.gmail.com
$ perl5122 -MDevel::Peek -we 'Dump(eval "v1.2.3_1")'
SV = PVMG(0xf01bb0) at 0xed3990
  REFCNT = 1
  FLAGS = (TEMP,RMG,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0xeefe60 "\1\2\37"\0
  CUR = 3
  LEN = 8
  MAGIC = 0xed7310
    MG_VIRTUAL = 0
    MG_TYPE = PERL_MAGIC_vstring(V)
    MG_LEN = 8
    MG_PTR = 0xec52b0 "v1.2.3_1"

Note that the PV is "\1\1\37" and the original "v1.2.3_1" in magic,
which is what gets used for version checks when you do "use Foo
v1.2.3_1".

This effectively makes it impossible for a pure-perl version.pm to
correctly deal with dotted-decimals with alphas.  (Short of capturing
and parsing Devel::Peek output)

Is there a good reason why the PV is \1\1\37 and not "\1\2\3\1"?  I
suspect that v-strings are uncommon except for version numbers and I
suspect that alpha v-strings are never used outside version numbers
except by accident.

-- David

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About