Associative array/Creation: Difference between revisions

m
Added subsections to Perl. Added Array Operation template
m (Creating Hash Structure moved to Creating an Associative Array: "Associative Array" is a more generic name.)
m (Added subsections to Perl. Added Array Operation template)
Line 1:
{{task}}
{{Array operation}}
 
In this task, the goal is to create an [[associative array]].
Line 6 ⟶ 7:
'''Interpeter:''' Perl
 
===Defining a Hash===
 
# using => key does not need to be quoted unless it contains special chars
Line 24 ⟶ 25:
);
 
===Defining a HashRef===
 
my $hashref = {
Line 33 ⟶ 34:
}
 
===Using a Hash===
 
print $hash{'key1'};
Line 41 ⟶ 42:
@hash{'key1', 'three'} = ('val1', -238.83);
 
===Using a HashRef===
 
print $hash->{'key1'};
Line 92 ⟶ 93:
for key, value in d.iteritems():
print key, value
 
Create a generic mapping function that applys a callback to elements in a list: