On 17 Sep 2000, Perl6 RFC Librarian wrote:

>    my $name = undef;
>    my($a, $b, $c, $d, $e, $f) = undef;

Well, these two get the result they want.  Try this code:

my($a, $b, $c, $d, $e, $f) = undef;
my %h = ( a => $a, b => $b, c => $c, d => $d, e => $e, f => $f );

while (my ($k, $v) = each %h)
{
    print defined $v ? "$k is defined" : "$k is undefined";
    print "\n";
}

it prints:

a is undefined
b is undefined
c is undefined
d is undefined
e is undefined
f is undefined


Why would anyone expect that assigning undef to anything would produce an
empty string.  That makes no sense at all.

>    my $name = empty;

what's wrong with $name = '';

>    my($a, $b, $c, $d, $e, $f) = empty;
>    my(@name, $age, %attrs) = empty;

What is the point of doing

my @name = ();

That's the same as:

my @name;

In fact, only for scalars does your proposed empty builtin do anything
different from my or local in terms of the value of the variable. 

> And its purpose is intuitive: It causes a value to become C<empty>,
> without being undefined. Note that it can also shorten code in some
> situations.

Well, I don't want to encourage people to needlessly 'initialize'
variables in Perl.

The only case where it makes a difference is where you do:

my $x;
$x .= 'a';
$x .= 'b';

and you'll get an unitialized value warning.  In that case, doing:

my $x = '';

is shorter and clearer.  There's no point in trying to 'initialize' arrays
or hashes, because you'll never get those warnings with it.

> Nonetheless, feel free to point out why this is a bad idea and I'll
> gladly retract it.

See the above ;)


-dave

/*==================
www.urth.org
We await the New Sun
==================*/




Reply via email to