david <[EMAIL PROTECTED]> wrote:
: 
: Wc -Sx- Jones wrote:
: 
: > explicit zero (0) or nothing ( or undefined.)
: > 
: > That is NOT true (it's not false either per se...)
: > 
: 
: this is impossible in Perl. show me an example
: where something is neither true nor false.

    Er, um, well ...

#!/usr/bin/perl

package foo;

use strict;
use warnings;

use Carp 'croak';
use overload bool => \&boolean;

sub new {
    return bless {
        value => undef,
        bool  => 1     }, 'foo';
}

sub value {
    my $self = shift;
    $self->{value} = shift if @_;
    return $self->{value} unless defined $self->{value};

    $self->{bool} = $self->{value} eq 'ambiguous' ? undef : $self->{value};

    return $self->{value};
}

sub boolean {
    my $self = shift;
    return $self->{value} if $self->{bool};

    croak "Sorry this value does not evaluate as either true or as false";
}

package main;
$|++;

use strict;
use warnings;
#use Data::Dumper 'Dumper';

my $foo = foo->new();

$foo->value(1);
print "true\n" if $foo;

$foo->value( undef );
print "false\n" unless $foo;

$foo->value( 'ambiguous' );
print "true\n" if $foo;

__END__

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to