Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerical values are stored as strings #18

Open
NickHibma opened this issue Dec 13, 2016 · 1 comment
Open

Numerical values are stored as strings #18

NickHibma opened this issue Dec 13, 2016 · 1 comment

Comments

@NickHibma
Copy link

When storing a number (e.g. 42) in DBM::Deep, it is retrieved as a string (e.g. "42"). This is generally not a problem unless you generate JSON and pass that onto Javascript which trips on this.

Example code:

use DBM::Deep;
use Devel::Peek;

my $v = 3.14;

my $db = DBM::Deep->new( "foo.db" );
$db->{s} = $v;

my $n_scalar = $v;
my $n_db = $db->{s};
my $n_db_add = $db->{s} + 0.0;

print "=====> Value:\n";
print Dump $n_scalar;
print "=====> Value run through db:\n";
print Dump $n_db;
print "=====> Value after conversion to number again:\n";
print Dump $n_db_add;

resulting in the following output:

SV = NV(0x7faed302d810) at 0x7faed302d828
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  NV = 3.14
=====> Value run through db:
SV = PVNV(0x7faed30034f0) at 0x7faed302d840
  REFCNT = 1
  FLAGS = (POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x7faed2d5d110 "3.14"\0
  CUR = 4
  LEN = 10
=====> Value after conversion to number again:
SV = NV(0x7faed302d858) at 0x7faed302d870
  REFCNT = 1
  FLAGS = (NOK,pNOK)
  NV = 3.14

The crucial bit is the NOK in the FLAGS section (IOK for integers, etc.).

@DrHyde
Copy link
Contributor

DrHyde commented Nov 8, 2023

This repo is no longer in use, I've replicated this ticket in the new repo at DBM-Deep#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants