[Israel.pm] List of all contexts in Perl

Gabor Szabo szabgab at gmail.com
Sun May 30 13:39:32 PDT 2010


And here is the code example that works that I wanted to send:

use warnings;
use 5.010;
use Want;

f();

say f(1);           # 1
say f(0);           # 0
say '-' x 10;       # ----------
if (f(1)) {
	say 1;	        # not reached
}
if (f(0)) {
	say 0;	        # 0
}
say '-' x 10;       # ----------
say f(0) ? 0 : 1;   # 0
say f(1) ? 1 : 0;   # 0

my $x = f(0) + f(1);    # ohoh

sub f {
	my $val = shift;

	if (want('BOOL')) {
		return $val ? 0 : 1;
	}
	if (want('LIST')) {
		return $val;
	}
	if (want('VOID')) {
		return;
	}

	die "ohoh\n";
}


More information about the Perl mailing list