I am trying to wrap my head around why the following test doesn't behave as I expected it to. I am trying to set a hash to a default boolean value unless the hash key exists. Here's an example:
Am I just having a case of the Monday mornings? I thought double quoting "0/1" would result in stringification and not an actual boolean.#!/usr/bin/perl use strict; use warnings; my %hash; $hash{KEY1} = "0"; $hash{KEY1} = "1" unless $hash{KEY1}; print "KEY1 = $hash{KEY1}\n"; # i expect KEY1 = 0 $hash{KEY1} = "FALSE"; $hash{KEY1} = "TRUE" unless $hash{KEY1}; print "KEY1 = $hash{KEY1}\n"; # i expect KEY1 = TRUE
In reply to Hashes and boolean values by osbosb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |