Re: convert string to number

2008-06-20 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: > >> - Forcing a conversion to a string or a numeric is easy in Perl, using >> >> $val.'' >> or >> $val+0 >> >> respectively. > > For my needs (which includes mod_perl) this is not complete. Having all > three personalities IOK/NOK/POK active at the

Re: convert string to number

2008-06-20 Thread Dr.Ruud
Rob Dixon schreef: > - Forcing a conversion to a string or a numeric is easy in Perl, using > > $val.'' > or > $val+0 > > respectively. For my needs (which includes mod_perl) this is not complete. Having all three personalities IOK/NOK/POK active at the same time before forking, saves

Re: convert string to number

2008-06-20 Thread Rob Dixon
Dr.Ruud wrote: > > Rob Dixon schreef: >> >> Dr.Ruud wrote: >>> >>> Rob Dixon wrote: 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

Re: convert string to number

2008-06-16 Thread Rob Dixon
William wrote: >> use strict; >> use warnings; >> >> use Devel::Peek qw/Dump/; >> >> my $numstr = sprintf("%4d", 1234); >> Dump $numstr; >> >> $numstr = sprintf("%05d", 1234); >> Dump $numstr; >> >> my $num = sprintf("%05d", 1234); >> $num += 0; >> Dump $num; >> >> **OUTPUT** >> >> SV = PV(0x365ec)

Re: convert string to number

2008-06-16 Thread Dr.Ruud
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 >> on

Re: convert string to number

2008-06-16 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: > >>> Maybe the other modules that you use, have Data::Dumper embedded? >> [...] >> >> Now I've been specific: all of those things were untrue. > > What can be wrong about a "maybe"? We're not talking about 'maybe there is a God' here, this is 'maybe pigs fly

Re: convert string to number

2008-06-16 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: >> Dr.Ruud: > >>> There is no real way to test if a value inside a variable has a >>> numeric "personality". [...] >> There is indeed a simple way to test in Perl whether a scalar value >> is being treated as a string > > I stated something about numeric, you a

Re: convert string to number

2008-06-16 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: > >> 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 st

Re: convert string to number

2008-06-16 Thread Dr.Ruud
Rob Dixon schreef: >> Maybe the other modules that you use, have Data::Dumper embedded? > [...] > > Now I've been specific: all of those things were untrue. What can be wrong about a "maybe"? -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additiona

Re: convert string to number

2008-06-16 Thread Dr.Ruud
Rob Dixon schreef: > Dr.Ruud: >> There is no real way to test if a value inside a variable has a >> numeric "personality". [...] > > There is indeed a simple way to test in Perl whether a scalar value > is being treated as a string I stated something about numeric, you about string. Do you see th

Re: convert string to number

2008-06-16 Thread Dr.Ruud
Rob Dixon schreef: > 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.

Re: convert string to number

2008-06-16 Thread Dr.Ruud
Rob Dixon schreef: > Dr.Ruud: >> Rob Dixon: >> I am not sure which of the above you consider not true, so I'll show >> it with a variant of your own code. > > without there being any 'above'. Nonsense. I left exactly what I assumed you meant with your "That is not true.". That is a basic function

Re: convert string to number

2008-06-16 Thread sisyphus
On Jun 15, 10:09 pm, [EMAIL PROTECTED] (William) wrote: > Hello, if I use the sprintf function it would give me a number STRING, but > not number, so I have to trick the string to become number by adding and > subtracting the number with 1. Is there a better way than this ? I want it to > be a n

Re: convert string to number

2008-06-16 Thread William
> use strict; > use warnings; > > use Devel::Peek qw/Dump/; > > my $numstr = sprintf("%4d", 1234); > Dump $numstr; > > $numstr = sprintf("%05d", 1234); > Dump $numstr; > > my $num = sprintf("%05d", 1234); > $num += 0; > Dump $num; > > **OUTPUT** > > SV = PV(0x365ec) at 0x3652c > REFCNT = 1

Re: convert string to number

2008-06-16 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: > >> Please try to quote relevant parts of the posts you respond to >> in future. > > I did, and I always do, and I'm proud of it. :) I think that is a matter of opinion, and mine is that you do not. For instance, no one has any idea what I said to prompt t

Re: convert string to number

2008-06-16 Thread Dr.Ruud
Rob Dixon schreef: > Dr.Ruud: >> Rob Dixon: >>> Dr.Ruud: That Data::Dumper prefers to print the numeric face of the variable, if available, is a matter of choice inside the code of Data::Dumper. Maybe the other modules that you use, have Data::Dumper embedded? >>> >>> That is n

Re: convert string to number

2008-06-16 Thread Dr.Ruud
Rob Dixon schreef: > Please try to quote relevant parts of the posts you respond to > in future. I did, and I always do, and I'm proud of it. :) Next time you write "That is not true.", be specific! -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For

Re: convert string to number

2008-06-15 Thread Rob Dixon
Dr.Ruud wrote: > Rob Dixon schreef: >> Dr.Ruud wrote: > >>> That Data::Dumper prefers to print the numeric face of the variable, >>> if available, is a matter of choice inside the code of Data::Dumper. >>> Maybe the other modules that you use, have Data::Dumper embedded? >> >> That is not true. >

Re: convert string to number

2008-06-15 Thread Dr.Ruud
William schreef: >> Testing with a numeric operator also "works", see below: >> >> $ perl -Mstrict -Mwarnings -MData::Dumper -wle' >>my $s = "1234"; >>print Dumper($s); >>print 1 if $s == 0; >>print Dumper($s); >>print 2 if $s eq "1234"; >>print Dumper($s); >> ' >> $VAR1 =

Re: convert string to number

2008-06-15 Thread Dr.Ruud
Rob Dixon schreef: > Dr.Ruud wrote: >> That Data::Dumper prefers to print the numeric face of the variable, >> if available, is a matter of choice inside the code of Data::Dumper. >> Maybe the other modules that you use, have Data::Dumper embedded? > > That is not true. I am not sure which of the

Re: convert string to number

2008-06-15 Thread William
> Testing with a numeric operator also "works", see below: > > $ perl -Mstrict -Mwarnings -MData::Dumper -wle' >my $s = "1234"; >print Dumper($s); >print 1 if $s == 0; >print Dumper($s); >print 2 if $s eq "1234"; >print Dumper($s); > ' > $VAR1 = '1234'; > > $VAR1 = 1234; >

Re: convert string to number

2008-06-15 Thread Rob Dixon
Dr.Ruud wrote: > William schreef: >> [*attribution dammit*] Ruud: > >>> There is no real way to test if a value inside a variable has a >>> numeric "personality". Variables can have multiple "personalities", >>> each with there own binary value. >>> >>> So maybe the problem just comes from the lea

Re: convert string to number

2008-06-15 Thread Dr.Ruud
William schreef: > [*attribution dammit*] Ruud: >> There is no real way to test if a value inside a variable has a >> numeric "personality". Variables can have multiple "personalities", >> each with there own binary value. >> >> So maybe the problem just comes from the leading zeroes that your >>

Re: convert string to number

2008-06-15 Thread William
> There is no real way to test if a value inside a variable has a numeric > "personality". Variables can have multiple "personalities", each with > there own binary value. > > So maybe the problem just comes from the leading zeroes that your > sprintf format added? Not exactly from the leading z

Re: convert string to number

2008-06-15 Thread Dr.Ruud
William schreef: > [attribution dammit] Ruud: >> my $number = 0+ $strNumber; >> >> or "in place": >> >> $strNumber += 0; >> >> But there really is no need! The first time you use the variable as a >> number, it will become a number (or rather a numeric reality will be >> added to it), whic

Re: convert string to number

2008-06-15 Thread William
> my $number = 0+ $strNumber; > > or "in place": > > $strNumber += 0; > > But there really is no need! The first time you use the variable as a > number, it will become a number (or rather a numeric reality will be > added to it), which is used in further numeric contexts haha instead o

Re: convert string to number

2008-06-15 Thread Dr.Ruud
William schreef: > Hello, if I use the sprintf function it would give me a number > STRING, but not number, so I have to trick the string to become > number by adding and subtracting the number with 1. Is there a better > way than this ? I want it to be a number data type and not string. > > e.g >

Re: convert string to number

2008-06-15 Thread Jeff Peng
On Sun, Jun 15, 2008 at 8:09 PM, William <[EMAIL PROTECTED]> wrote: > > my $strNumber = sprintf("%04d", 123); instead of that, you would say: my $strNumber = sprintf("%d", 123); This is already a number. -- Jeff Peng - [EMAIL PROTECTED] Professional Squid supports in China http://www.ChinaSqu

convert string to number

2008-06-15 Thread William
Hello, if I use the sprintf function it would give me a number STRING, but not number, so I have to trick the string to become number by adding and subtracting the number with 1. Is there a better way than this ? I want it to be a number data type and not string. e.g my $strNumber = sprintf("