[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: uninitialized vs. undefined



[Quoting Tom Christiansen, on January 13 2000, 14:52, in "Re: uninitialized vs"]
> >I've always felt there must be a difference between
> 
> >  my @a;	# undefined
> >  my @a = ();	# defined but empty
> 
> >I was slightly disappointed to find out that 5.005_63 deprecates
> >defined(@a) to tell the difference.
> 
> But it doesn't do that!

I know. It's one of those 'missed opportunities'.

An uninitialized scalar gets an undefined value, which is different
from any other value the scalar can take (although, when used,
undefined works out as being 0 or "").

Likewise, an uninitialized array should have an undefined value,
which is different from an empty array (although an uninitialized
value behaves as ()). 'defined(@a)' would have been an nice way to
test this. 

I wonder if any programs would break if 
  my @a = undef;
would be equivalent to
  my @a;
instead of 
  my @a = (undef);
and
  defined(@a)
would suddenly fail on an uninitialized array.

-- Johan

PS: Likewise, hashes.


Follow-Ups from:
Tom Christiansen <tchrist@chthon.perl.com>
References to:
JVromans@squirrel.nl (Johan Vromans)
Tom Christiansen <tchrist@chthon.perl.com>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]