Rob Dixon schreef: > Dr.Ruud: >> Rob Dixon: >>> A scalar cannot have multiple 'personalities' - it can have a >>> maximum of two (its inherent type and a string equivalent) at any >>> one time, but usually has only one. >> >> It can at least have 3: an integer numeric one, a floating numeric >> one, and a string one. It can have more. > > No. It can be just a string; an integer and a string; a double and a > string; or a reference (pointer) and a string. After that there's > some weird stuff that goes on with tied scalars and so on. Basically > every scalar data type keeps space for a pointer to its string > equivalent as well, presumably because it's a useful thing to > remember once it has been evaluated once.
1: all three of IOK and NOK and POK are set. perl -Mstrict -Mwarnings -MData::Dumper -MDevel::Peek=Dump -wle' my $s = "x"; defined($s) and do { no warnings "numeric"; $s eq "" and 1; $s == $_ and 1 for 0, 0.1; }; print "\n", Dumper($s); Dump $s; ' $VAR1 = 'x'; SV = PVNV(0x8a19cb8) at 0x89bad2c REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x89b6548 "x"\0 CUR = 1 LEN = 2 2: lossy, so no IOK. perl -Mstrict -Mwarnings -MData::Dumper -MDevel::Peek=Dump -wle' my $s = "122.99999999999999"; defined($s) and do { no warnings "numeric"; $s eq "" and 1; $s == $_ and 1 for 0, 0.1; }; print "\n", Dumper($s); Dump $s; ' $VAR1 = '122.99999999999999'; SV = PVNV(0x88aba40) at 0x884cc3c REFCNT = 1 FLAGS = (PADBUSY,PADMY,NOK,POK,pIOK,pNOK,pPOK) IV = 122 NV = 123 PV = 0x8848700 "122.99999999999999"\0 CUR = 18 LEN = 19 3: a numeric string, touched by numeric comparisons, so returned as a number by Dumper; again all of IOK, NOK and POK are set. perl -Mstrict -Mwarnings -MData::Dumper -MDevel::Peek=Dump -wle' my $s = "123"; $ARGV[0] and defined($s) and do { no warnings "numeric"; $s eq "" and 1; $s == $_ and 1 for 0, 0.1; }; print "\n", Dumper($s); Dump $s; ' 1 $VAR1 = 123; SV = PVNV(0x8160dd0) at 0x8101be8 REFCNT = 1 FLAGS = (PADBUSY,PADMY,IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 123 NV = 123 PV = 0x80fd450 "123"\0 CUR = 3 LEN = 4 I would say that 1 and 3 have three personalities. And 2 has nearly three. :) 4: make $s blessed too. perl -Mstrict -Mwarnings -MData::Dumper -MDevel::Peek=Dump -wle' my $s = "123"; bless \$s, "test"; defined($s) and do { no warnings "numeric"; $s eq "" and 1; $s == $_ and 1 for 0.1, 0; }; print "\n", Dumper($s); Dump $s; ' $VAR1 = 123; SV = PVMG(0x90f5618) at 0x9068c44 REFCNT = 1 FLAGS = (PADBUSY,PADMY,OBJECT,IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 123 NV = 123 PV = 0x9064460 "123"\0 CUR = 3 LEN = 4 STASH = 0x9063cf4 "test" That last one is an example of what I named "more". -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/