waynerasm has asked for the wisdom of the Perl Monks concerning the following question:
I am using Perl 5.22.1 (Ubuntu 16.04 LTS) and am trying to understand why referencing a hash value changes the internal type of the value and how to identify what the type is in the first place. By way of example:
outputs 1~{"a":1}
outputs 1~{"a":"1"}
However,
outputs 1~{"a":"1"} NB {a=>1} at start
yet ostensibly no explicit change was made to $x{a} further more the reverse does not apply i.e. I can't change it back via reference only; such as print length($x{a}),$x{a}+0,... does not lead to encode_json(\%x) returning {"a":1}
So BUG, lack of understanding on my part? And how does one determin that $x{a} is a number verses a string?
As always, thanks in advance for any understanding shared.
For those that ask why do you want to know, becasue I am writting JSON to a field in MySQL Database which will be consumed via R (amongst other avenues) and in R "1"+1 -> ERROR. I need to ensure the JSON value pairs are consistent so it appears I need to be very careful (or use another version or Perl?) between generating the Hash and encoding it before writting to the Database.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hash value typing
by haukex (Archbishop) on Jun 10, 2018 at 10:12 UTC | |
|
Re: Hash value typing
by Anonymous Monk on Jun 10, 2018 at 10:17 UTC | |
by waynerasm (Initiate) on Jun 10, 2018 at 14:31 UTC | |
by shmem (Chancellor) on Jun 10, 2018 at 16:05 UTC | |
by waynerasm (Initiate) on Jun 11, 2018 at 01:10 UTC | |
by haukex (Archbishop) on Jun 10, 2018 at 22:24 UTC | |
by waynerasm (Initiate) on Jun 11, 2018 at 01:02 UTC |