R
Roy Johnson
I apologize for being so late to this party, but I do think I have an
idea worth considering.
//= will be forthcoming in perl6 to handle defaulting undefined values
(vs. merely false ones). In the threads discussing it, there was some
noise made about needing another operator for exists, and maybe a
special alternative to the (ever so rarely used) &&=, etc.
It occurred to me that maybe what ought to be done was to make tests
act as assigners (or yield lvalues, sort of) in certain situations --
in particular, in situations where ||= or &&= is specified, assign to
the argument being tested:
defined($var) ||= 'default';
exists($hash{$key}) &&= 'replacement';
To me, this reads pretty well. From a syntax standpoint, it's very
irregular, but that hasn't stopped Perl in the past.
idea worth considering.
//= will be forthcoming in perl6 to handle defaulting undefined values
(vs. merely false ones). In the threads discussing it, there was some
noise made about needing another operator for exists, and maybe a
special alternative to the (ever so rarely used) &&=, etc.
It occurred to me that maybe what ought to be done was to make tests
act as assigners (or yield lvalues, sort of) in certain situations --
in particular, in situations where ||= or &&= is specified, assign to
the argument being tested:
defined($var) ||= 'default';
exists($hash{$key}) &&= 'replacement';
To me, this reads pretty well. From a syntax standpoint, it's very
irregular, but that hasn't stopped Perl in the past.