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

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

Thread Previous | Thread Next
From:
William R Ward
Date:
October 29, 1999 02:00
Subject:
Re: A plea for Or-Defined: ordef, |||, |||=
Message ID:
m2g0yutucc.fsf@komodo.bayview.com
"Mark Mielke" <markm@nortelnetworks.com> 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.

--Bill.

-- 
William R Ward        hermit@bayview.com      http://www.bayview.com/~hermit/
-----------------------------------------------------------------------------
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About