automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with CVS HEAD, bootstrap, Perl 5.005_003


From: Eric Siegerman
Subject: Re: Problem with CVS HEAD, bootstrap, Perl 5.005_003
Date: Fri, 11 Apr 2003 12:20:55 -0400
User-agent: Mutt/1.2.5i

On Fri, Apr 11, 2003 at 08:44:22AM +0200, Alexandre Duret-Lutz wrote:
> >>> "Richard" == Richard Dawe <address@hidden> writes:
>  Richard> iolanthe:~/src/automake =] ./bootstrap 
>  Richard> delete argument is not a HASH element or slice at
>  Richard> automake-1.7a/Automake/DisjConditions.pm line 514.
>  Richard> BEGIN failed--compilation aborted at ./automake.tmp line 130.
> 
> That probably something we should fix.  How do you delete a list
> element in old Perl versions?

I don't think there is a way.  But then, you can't test list
elements for existence (as opposed to definedness) either.  In
Perl 5.005_03, neither delete() nor exists() is defined on list
members; they only accept hash members as arguments.

The closest you can get for a list member is to undefine it:
        $array[$subscript] = undef;
and test it with defined() rather than exists().

Following are the relevent sections of perlfunc(1) from 5.005_03.

======================== From Perl 5.005_03 ============================
=item delete EXPR

Deletes the specified key(s) and their associated values from a hash.
For each key, returns the deleted value associated with that key, or
the undefined value if there was no such key.  Deleting from C<$ENV{}>
modifies the environment.  Deleting from a hash tied to a DBM file
deletes the entry from the DBM file.  (But deleting from a C<tie()>d hash
doesn't necessarily return anything.)

The following deletes all the values of a hash:

    foreach $key (keys %HASH) {
        delete $HASH{$key};
    }

And so does this:

    delete @HASH{keys %HASH}

But both of these are slower than just assigning the empty list
or undefining it:

    %hash = ();         # completely empty %hash
    undef %hash;        # forget %hash every existed

Note that the EXPR can be arbitrarily complicated as long as the final
operation is a hash element lookup or hash slice:

    delete $ref->[$x][$y]{$key};
    delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};

=item exists EXPR

Returns TRUE if the specified hash key exists in its hash array, even
if the corresponding value is undefined.

    print "Exists\n"    if exists $array{$key};
    print "Defined\n"   if defined $array{$key};
    print "True\n"      if $array{$key};

A hash element can be TRUE only if it's defined, and defined if
it exists, but the reverse doesn't necessarily hold true.

Note that the EXPR can be arbitrarily complicated as long as the final
operation is a hash key lookup:

    if (exists $ref->{A}->{B}->{$key})  { }
    if (exists $hash{A}{B}{$key})       { }

Although the last element will not spring into existence just because
its existence was tested, intervening ones will.  Thus C<$ref-E<gt>{"A"}>
and C<$ref-E<gt>{"A"}-E<gt>{"B"}> will spring into existence due to the
existence test for a $key element.  This happens anywhere the arrow
operator is used, including even 

    undef $ref;
    if (exists $ref->{"Some key"})      { }
    print $ref;             # prints HASH(0x80d3d5c)

This surprising autovivification in what does not at first--or even
second--glance appear to be an lvalue context may be fixed in a future
release.

========================================================================

--

|  | /\
|-_|/  >   Eric Siegerman, Toronto, Ont.        address@hidden
|  |  /
My Wine works.  However it crashes about half the time on startup.
Apparently their simulation of windoze API is getting too accurate.  :)
        - Kyle Sallee





reply via email to

[Prev in Thread] Current Thread [Next in Thread]