public
anonymous / gist:4270506
Created

  • Download Gist
gistfile1.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!perl
use strict;
use warnings;
use Test::More;
 
sub r_explicit { return 0; }
sub r_bare { return; }
 
# Probably not what you expected
my %hash = (
first => r_bare,
second => r_explicit,
);
 
ok( exists $hash{'first'}, "'first' exists" );
ok(! exists $hash{'second'}, "'second' unset" );
 
# Not list context, as it happens
ok(! r_explicit, "r_explicit is false" ); # Passes
 
# Works like you'd hope
if ( r_explicit ) {
fail("r_explicit is false");
} else {
pass("r_explicit is false");
}
 
# Jumping through some real hoops here...
my $wrong_answer =()= r_explicit;
ok( $wrong_answer, "I blame the =()= operator" );
 
my @wrong_answer = r_explicit;
if ( @wrong_answer ) {
pass("Who evaluates a list for truth, anyway?");
} else {
fail("Who evaluates a list for truth, anyway?");
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.