View Single Post
  #9   (View Single Post)  
Old 7th February 2014
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

From the "Perl Cookbook" chapter about hashes by Christiansen and Torkington:

Quote:
... problems caused by confusing existence, definedness, and truth can multiply like rabbits.
They give the following example:
Code:
#!/usr/bin/perl

use warnings;
use strict;

my %age = ();
my $thing;

$age{'Toddler'} = 3;
$age{'Unborn'} = 0;
$age{'Phantasm'} = undef;

foreach $thing('Toddler', 'Unborn', 'Phantasm', 'Relic') { 
   print "$thing: ";
   print "Exists " if exists $age{$thing};
   print "Defined " if defined $age{$thing};
   print "True " if $age{$thing};
   print "\n";
}
The output:
Code:
Toddler: Exists Defined True 
Unborn: Exists Defined 
Phantasm: Exists 
Relic:
A summary of their explanation:

$age{'Unborn'} fails the truth test because the number 0 is one of Perl's false values.

$age{'Phantasm'} only exists because it has been given a value in the hash. Because that value is 'undef' it does not pass the test for definedness.
'undef' is also a Perl false value.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote