in reply to Re^2: RFC: "assignary" operator ?= :
in thread RFC: "assignary" operator ?= :

This is a pretty cute alternative:

sub empty ($) :lvalue { if ($_[0]) { require Carp; if (eval { require PadWalker }) { my $varname = PadWalker::var_name(1, \$_[0]); Carp::croak("$varname is not empty, stopped"); } Carp::croak("Variable is not empty, stopped"); } $_[0]; } # Asserts that $var1 is "empty" (i.e. the empty string, 0, or undef) a +nd assigns $var2 as the new value. empty $var1 = $var2; # Can also be used like this to assert $var1 is empty without assignin +g a new value. empty $var1;

Replies are listed 'Best First'.
Re^4: RFC: "assignary" operator ?= :
by LanX (Saint) on Dec 08, 2019 at 01:11 UTC
    nice! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice