!!!1 is nothing?

hw via beginners <[email protected]> Mon, 04 May 2026 02:00:44 +0200
Newsgroups gmane.comp.lang.perl.beginners
Message-ID <[email protected]>
Hi,

I'm wondering why I get nothing from a 'direct' version of:


sub get_ison($self) {
    my $stuff =3D $self->get_status;

    # yields "'output' =3D> !!1" when on and "'output' =3D> !!0" when off
    if($stuff->{output} =3D=3D 1) {
	return 1;
    }

    return 0;
}

sub get_isoff($self) {
    # for unknown reasons, "return !$self->get_ison" yields nothing
    if($self->get_ison =3D=3D 1) {
	return 0;
    }

    return 1;
}


$stuff in this case is the result of basically:


use LWP::UserAgent();
use JSON::Parse qw(parse_json);

    my $ua =3D LWP::UserAgent->new();
    my $response =3D $ua->get("http://example.org");
    my $stuff =3D parse_json( $response->decoded_content );


When I use


sub get_isoff($self) {
    return !$self->get_ison;
}


instead of the 'indirect' way above and have


say $switch->get_isoff;


in the caller, it prints a blank line instead of either 1 or 0.

Any idea why that is?  Is there some kind of wierd evaluating of '!!1'
or '!!0' going on?  Even '!!!1' should evaluate to 0 and not to
nothing.

When I do the same http request with a web browser, I get


output:	true


which is what I expected in perl as well ...

-- 
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/