RE: [EXTERNAL] Re: select decimal column from mysql

2021-12-20 Thread Fennell, Brian
Before someone points out that my description of perl variables is incomplete:

Here are the extra details for the very curious:

https://perldoc.perl.org/perlguts#Datatypes

https://metacpan.org/pod/Scalar::Util

https://perldoc.perl.org/Scalar::Util#dualvar

https://perldoc.perl.org/Scalar::Util#isdual

https://perldoc.perl.org/Scalar::Util#isvstring

https://perldoc.perl.org/Scalar::Util#looks_like_number

https://metacpan.org/release/NWCLARK/perl-5.8.8/view/pod/perlapi.pod

https://metacpan.org/pod/POSIX::1003::Math

https://www.perl.com/pub/2012/06/perlunicook-further-resources.html/

https://perldoc.perl.org/perlapi

https://perldoc.perl.org/perlembed

https://perldoc.perl.org/Devel::Peek

https://www.nntp.perl.org/group/perl.perl5.porters/2015/11/msg232974.html




-Original Message-
From: Fennell, Brian
Sent: Monday, December 20, 2021 10:14 AM
To: john miky ; dbi-users@perl.org
Subject: RE: [EXTERNAL] Re: select decimal column from mysql

Variables in perl are “untyped” or better yet “dynamically typed”.
Every variable is a string but will behave like a int or float in the right 
context.
Conversions from string to int to float and back to string happen automatically 
and silently.
This may be surprising and confusing if you are coming from java.

Example:

perl -e '$v = "123" ; print $v . "\n" ; $v += 2 ; print $v . "\n"; $v /= 2.0 ; 
print $v . "\n"; print length($v) . "\n"; $v = "(" . $v . ")"; print $v . "\n"'
123
125
62.5
4
(62.5)



From: john miky 
Sent: Monday, December 20, 2021 1:28 AM
To: dbi-users@perl.org
Subject: [EXTERNAL] Re: select decimal column from mysql

sorry, please ignore this stupid question, 0.015 is > 0

On Mon, Dec 20, 2021 at 2:19 PM john miky <mailto:gb2...@gmail.com> wrote:
hmm. it is perl's "problem", not dbi.

On Mon, Dec 20, 2021 at 1:20 PM john miky <mailto:gb2...@gmail.com> wrote:
hi,

I select a decimal column, from mysql with dbi, the value 0.015 for example,  
my ($v) = $dbh->selectrow_array("select price from test limit 1") it is greater 
than 0 in perl.

What's the proper way to get a float value ?



The information contained in this electronic mail transmission is intended only 
for the use of the individual or entity named in this transmission. If you are 
not the intended recipient of this transmission, you are hereby notified that 
any disclosure, copying or distribution of the contents of this transmission is 
strictly prohibited and that you should delete the contents of this 
transmission from your system immediately. Any comments or statements contained 
in this transmission do not necessarily reflect the views or position of Radial 
or its subsidiaries and/or affiliates.




RE: [EXTERNAL] Re: select decimal column from mysql

2021-12-20 Thread Fennell, Brian
Variables in perl are “untyped” or better yet “dynamically typed”.
Every variable is a string but will behave like a int or float in the right 
context.
Conversions from string to int to float and back to string happen automatically 
and silently.
This may be surprising and confusing if you are coming from java.

Example:

perl -e '$v = "123" ; print $v . "\n" ; $v += 2 ; print $v . "\n"; $v /= 2.0 ; 
print $v . "\n"; print length($v) . "\n"; $v = "(" . $v . ")"; print $v . "\n"'
123
125
62.5
4
(62.5)



From: john miky 
Sent: Monday, December 20, 2021 1:28 AM
To: dbi-users@perl.org
Subject: [EXTERNAL] Re: select decimal column from mysql

sorry, please ignore this stupid question, 0.015 is > 0

On Mon, Dec 20, 2021 at 2:19 PM john miky  wrote:
hmm. it is perl's "problem", not dbi.

On Mon, Dec 20, 2021 at 1:20 PM john miky  wrote:
hi,

I select a decimal column, from mysql with dbi,
the value 0.015 for example,  my ($v) = $dbh->selectrow_array("select price 
from test limit 1")
it is greater than 0 in perl.

What's the proper way to get a float value ?



The information contained in this electronic mail transmission is intended only 
for the use of the individual or entity named in this transmission. If you are 
not the intended recipient of this transmission, you are hereby notified that 
any disclosure, copying or distribution of the contents of this transmission is 
strictly prohibited and that you should delete the contents of this 
transmission from your system immediately. Any comments or statements contained 
in this transmission do not necessarily reflect the views or position of Radial 
or its subsidiaries and/or affiliates.