Anonymous user
Associative array/Creation: Difference between revisions
Undo revision 106217 by 208.74.121.102 Shorter was less informative.
(→{{header|Perl}}: Made the example shorter. Information on the difference between a reference and a regular hash is not important.) |
(Undo revision 106217 by 208.74.121.102 Shorter was less informative.) |
||
Line 1,629:
=={{header|Perl}}==
===Hash===
<lang perl>▼
Definition:
<lang perl># using => key does not need to be quoted unless it contains special chars
my %hash = (
</lang>▼
key1 => 'val1',
'key-2' => 2,
three => -238.83,
4 => 'val3',
);
# using , both key and value need to be quoted if containing something non-numeric in nature
my %hash = (
'key1', 'val1',
'key-2', 2,
'three', -238.83,
4, 'val3',
▲);</lang>
Use:
<lang perl>print $hash{key1};
$hash{key1} = 'val1';
@hash{'key1', 'three'} = ('val1', -238.83);</lang>
===HashRef===
Definition:
<lang perl>my $hashref = {
key1 => 'val1',
'key-2' => 2,
three => -238.83,
4 => 'val3',
Use:
<lang perl>print $hash->{key1};
$hash->{key1} = 'val1';
@hash->{'key1', 'three'} = ('val1', -238.83);</lang>
=={{header|Perl 6}}==
|