Bart Van der Donck wrote:
Richard Cornford wrote:
>[...] Can you cite an example of something that unambiguously
is an associative array that would treat keys of the same type
differently depending on the value of those keys?
Sure.
#!/usr/bin/perl
use strict;
use warnings;
$ENV{"aKey"} = "aValue"; # (like js' ENV["aKey"] = "aValue")
print "(1) " . $ENV{"aKey"} . "\n";
print "(2) " . $ENV{"SYSTEMROO T"} . "\n";
$INC{"aSecondKe y"} = "aSecondVal ue";
print "(3) " . $INC{"aSecondKe y"} . "\n";
print "(4) " . $INC{"strict.pm "} . "\n";
It says:
(1) aValue
(2) C:\WINDOWS
(3) aSecondValue
(4) c:/Perl/lib/strict.pm
If I am reading this correctly we can see two assignments using string
keys which appear to both be successful, and four retrievals using
string keys, which all appear to be equally successful. This does not
demonstrate any treating of keys differently based upon the value of the
key.
I suppose you are suggesting that the second of each pair of retrievals
is treating the keys differently as they have (supposedly) not been
assigned. But that is not reasonable as your code does not show the
instantiation of the objects, or the intervening treatments of them.
What is really needed is a demonstration that writing to a 'significant'
key can fail to assign a value (or that the value will be modified in
the process).
I know Perl is not a fair game here, but this is what's going on:
hashes (=associative arrays) %INC, %ENV and %SIG hold special
pre-defined values for certain keys.
These 'associative arrays' are part of the execution environment, aren't
they? That may be used to argue that they are no longer associative
arrays, but more interfaces to the environment. But I would be more
interested in seeing them reject/modify an assignment before rejecting
the claim that they are associative arrays. As it is I don't see any
evidence of them treating keys differently depending on the actual value
of the key, only evidence that some key/value pairs have been assigned
prior to the object being exposed. And as a result these are not exempts
of associative arrays that would treat keys of the same type differently
depending on the value of those keys.
Other keys are free to be filled
by the programmer.
But can the programmer assign to the system defined keys (without
modification of the value or side effects)?
Does this mean that there are no associative arrays in
Perl ? Not at all.
I have not seen that these objects are unambiguously associative arrays,
though the code you posted does not contradict that, but even if they
were not that could not be extended to saying that Perl had no
associative arrays. But javascript only has one object type, either that
object is an associative array or javascript has no associative arrays,
it is that black and white.
It means that a Perl programmer must be aware of how
associative arrays work in Perl,
Surely it means that Pearl programmers have to be aware that these
particular associative arrays are partly pre-populated with significant
keys?
and that some keys are not available for those
hashes.
Yes, does it have any implications for when they create a new hash from
scratch?
Also, Perl hashes know other particularities : no sorting
possibilities, multi-dimensional hashes, (de)referencing
to other vars in hash values,
None of which help the decision either way.
additional forbidden keys from modules, etc.
But that may be very significant. Can you say more? Or does this only
apply to the special pre-populated hashes you started with?
Richard.