Leopold Toetsch wrote: > Nick Glencross wrote: > > > Having read up in the past on Perl5 internals, it seems to be > > capable of keeping more than one representation of a Scalar active > > at a time. > > > > Anyone know if there are plans to do this kind of optimisation? > > I don't think, this is an optimization at least not for an average > program. Processor cycles are cheap these days, memory access still > isn't. A lot of my recent work was to reduce the scalar size from 32 > to 20 byte (32bit). This almost doubles performance on accessing huge > (1e6) data sets. > OTOH, if there is a clear need for an e.g. NumStr hybrid, then it > should be a separate PMC which is used, when $HL says so by some > traits.
There is indeed a clear need for it -- the values produced by $! (and by the related $^E) are dual int/string values. If you do: $! = 3; my $x = $!; printf "%d: %s\n", $x, $x; It outputs, on my system: "3: No such process", indicating that the value in $x contains both a string and a number, in a way that cannot be obviously generated one from the other. Also, the module Scalar::Util has a dualvar() subroutine, which produces int/string values of this type. Also, consider the following: [Windows 95] C:\WINDOWS>perl -we "$x = '';" -e "$x + 0;" -e "$x + 0;" Useless use of addition (+) in void context at -e line 2. Useless use of addition (+) in void context at -e line 3. Argument "" isn't numeric in addition (+) at -e line 2. [Windows 95] C:\WINDOWS>perl -we "$x = '1x';" -e "$x + 0;" -e "$x + 0" Useless use of addition (+) in void context at -e line 2. Useless use of addition (+) in void context at -e line 3. Argument "1x" isn't numeric in addition (+) at -e line 2. Note that the 'Argument ... isn't numeric' warning only appeared once for each of these one-liners -- this is because $x was upgraded from a mere "" to a dualvar("", 0). We don't *need* to do things this way, of course -- but that's how perl5 does it, and we might or might not find this to be the simplest solution. Another possibility is to have, for our String PMC class, a flag indicating not to warn when numifiying. The first time we numify a string which isn't really a proper number, we warn, then set this flag. After that, we still have to numify (since we didn't cache the extracted number), but we don't warn due to seeing the flag. But we'd still need some sort of dualvar/NumStr for $! and $^E. -- $a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca );{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "[EMAIL PROTECTED] ]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}