On Mon, Sep 9, 2013 at 6:00 AM, Hans Ginzel <h...@matfyz.cz> wrote:

> Hello!
>
> Is there a shorter way to write $a = ! $a, please?
>
> Something analogous to ++ and -- operators like $a !! or !! $a would negate
> the variable $a and return its previous or new value respectively.
>
> Best regards


Not really. But you can toy around with operator overloading to make it
work, or abuse prototypes and do this:

sub b   (*) { my $o = $_[0]; $_[0] = !!$_[0]; $o } # b for bool,
sub nb (*) { my $o = $_[0]; $_[0] = !$_[0]; $o  } # nb for not bool. 100%
maintainable and understandable

my $v = 10;
nb $v;
say $v;
nb $v;
say $v

There might be more magical ways to do this (read: Devel::CallParser), but
you'll have to dig for those yourself.

Reply via email to