develooper Front page | perl.perl5.porters | Postings from October 1999

Re: A plea for Or-Defined: ordef, |||, |||=

Thread Previous | Thread Next
William R Ward
October 29, 1999 02:00
Re: A plea for Or-Defined: ordef, |||, |||=
Message ID:
"Mark Mielke" <> writes:
>      my $a   : string;
>      $a ||= $b;  # Just works "right"

I have trouble understanding how this would work - strings can still
be false if they are "0" or "".

Anyway, I've been not following p5p closely and lately I have started
poking my nose in again.  I notice examples like you are giving above
with a "my $a : string" or "our $FOO : export" being bandied about,
and I'm not clear on what the new ": keyword" thing is supposed to be.

However, would this work?

   my $a : default(shift, 42);

The meaning of this would be the same as this:

   my $a = shift;
   $a = 42 unless defined $a;

One could give a list of values in the list after ": defined", and the
first non-undef one would be assigned to $a.


William R Ward
The secret of being creative is making something that's not very new
but just a little bit different in the right direction - Marvin Minsky

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About