Skip to content

Instantly share code, notes, and snippets.

@dagolden
Created February 5, 2014 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagolden/8834407 to your computer and use it in GitHub Desktop.
Save dagolden/8834407 to your computer and use it in GitHub Desktop.
use strict;
use YAML::Tiny;
#######
# Make an object from "data":
my $data = "000 000";
my $hash1 = {split /\s/, $data};
print Dump $hash1; # expect '000': '000' (Works)
# Attempt to force numeric
$hash1->{'000'} += 0;
print Dump $hash1; # expect '000': 0 (Works)
#######
# User created object:
my $hash2 = { 000 => 0 };
# NOTE: This implies all Perl numeric keys dumped should be quoted.
print Dump $hash2; # expect '0': 0 (Works)
# Attempt force to string:
$hash2->{0} = $hash2->{0} . ""; # (Works)
# my $hash2->{0} .= ""; # (Doesn't Work) Dumps: '0': ''
# my $hash2->{0} = "$hash2->{0}"; # (Works)
print Dump $hash2; # expect '0': '0' (Works)
$hash2->{0} = 42;
print Dump $hash2; # expect '0': 42 (Works)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment