mkhan has asked for the wisdom of the Perl Monks concerning the following question:
In the above code, the mere printing of the hash value adds double quotes to the timeout value in the json as shown in the output.use JSON; $params->{timeout} = 2000; $body->{"timeout"} = (defined $params->{timeout}?$params->{timeout} : +3000); print "$body->{timeout}\n"; #<-----suspect line my $body_string = to_json($body); print "$body_string";
Now if you remove the "suspect line" from the above code:Output: 2000 {"timeout":"2000"}
use JSON; $params->{timeout} = 2000; $body->{"timeout"} = (defined $params->{timeout}?$params->{timeout} : +3000); my $body_string = to_json($body); print "$body_string";
In the second output, the value 2000 wasn't wrapped in quotes. I find it really peculiar as to why the mere printing of the hash value changes the behavior of the output??Output: {"timeout":2000}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Peculiar incident: printing a variable changes its type
by tobyink (Canon) on Nov 13, 2013 at 09:28 UTC | |
by choroba (Cardinal) on Nov 13, 2013 at 14:23 UTC | |
|
Re: Peculiar incident: printing a variable changes its type
by mje (Curate) on Nov 13, 2013 at 09:23 UTC | |
|
Re: Peculiar incident: printing a variable changes its type
by KurtZ (Friar) on Nov 13, 2013 at 14:07 UTC |