Skip to content

Instantly share code, notes, and snippets.

@dankogai
Created April 1, 2013 09:35
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 dankogai/5284015 to your computer and use it in GitHub Desktop.
Save dankogai/5284015 to your computer and use it in GitHub Desktop.
boolean best practice
#!/usr/bin/env perl
use v5.12;
use boolean -truth;
use JSON;
sub boolean::TO_JSON() { !$_[0] ? \0 : \1 }
my $json = JSON->new->convert_blessed;
my $bools = { false => ( 0 == 1 ), true => ( 1 == 1 ) };
eval { say encode_json($bools) };
warn $@ if $@;
say $json->encode($bools);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment