develooper Front page | perl.perl5.porters | Postings from August 2001

Re: vstring guidance needed

Thread Previous | Thread Next
From:
John Peacock
Date:
August 20, 2001 08:03
Subject:
Re: vstring guidance needed
Message ID:
3B8124DB.6439A5BD@rowman.com
Rafael Garcia-Suarez wrote:
> 
> On 2001.08.20 15:21:01 +0200 John Peacock wrote:
> > Actually, the bit in perl.c which sets up the $] system variables
> > sets both PV and NV for the Perl version.  I'll be changing that to
> > call the new_vstring code instead.
> 
> Beware : $] stores both an NV and a PV for performance only -- to avoid
> conversions. This is similar to a SV that holds an NV and also has been
> used in string context. With perl 5.6.1 :
> 
> $ perl -MDevel::Peek -e 'Dump $]'
> SV = PVNV(0x80f1030) at 0x80fb160
>   REFCNT = 1
>   FLAGS = (NOK,POK,READONLY,pNOK,pPOK)
>   IV = 0
>   NV = 5.006001
>   PV = 0x8100a60 "5.006001"\0
>   CUR = 8
>   LEN = 10
> 
> As you see the PV is not a version string. 

That's just the oversight I am considering fixing.

> The version string is in $^V, but $^V
> has also the numerical value :
> 
> $ perl -MDevel::Peek -e 'Dump $^V'
> SV = PVNV(0x80f0dd8) at 0x80f017c
>   REFCNT = 2
>   FLAGS = (NOK,POK,READONLY,pNOK,pPOK,UTF8)
>   IV = 0
>   NV = 5.006001
>   PV = 0x80f53b0 "\5\6\1"\0
>   CUR = 3
>   LEN = 5

This would also get changed to supress the numeric portion if I have 
my way with it.

> 
> You can't ensure this at compile-time only. Example : $scalar < $^V will
> yield a problem : the compiler will need to know that $^V contains a vstring. 

$^V will always contain a v-string, by design, so the parser can back up 
and replace the token for "<" with "lt" couldn't it?  All of the 
v-string conversions happen during the compilation phase; either it is a 
bareword v-string (and the tokenizer catches it) or UNIVERSAL::VERSION
gets it during "use" or "require" (via Exporter::require_version).

> And
> this is a simple example. Looks like you will need to forget version comparison
> with '<', or introduce a new type of magic (better than a VOK flag or messing with
> pNOK). In fact, '<' for now works only for the vstring held in $^V.

Example code for creating new magic greatly appreciated. ;~)

> '<' doesn't need to work with vstrings.

I am leaning in that direction myself.  I just find more pieces to fix
the harder I look. :~(

John

--
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4720 Boston Way
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747

Thread Previous | 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