osbosb has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Hashes and boolean values
by moritz (Cardinal) on Jan 23, 2012 at 13:12 UTC | |
by osbosb (Monk) on Jan 23, 2012 at 13:24 UTC | |
by moritz (Cardinal) on Jan 23, 2012 at 13:26 UTC | |
by osbosb (Monk) on Jan 24, 2012 at 15:41 UTC | |
by JavaFan (Canon) on Jan 23, 2012 at 14:12 UTC | |
|
Re: Hashes and boolean values
by osbosb (Monk) on Jan 23, 2012 at 13:11 UTC | |
|
Re: Hashes and boolean values
by Anonymous Monk on Jan 23, 2012 at 16:05 UTC |