Unit3 B
Unit3 B
Structured Data
Types
Arrays
Records
Definitions
• data type
– collection of data objects
– a set of predefined operations
• descriptor : collection of attributes for a
variable
• object : instance of a user-defined
(abstract data) type
• Arrays
– aggregate of homogeneous data
elements indexed by its position
• Associative arrays
– unordered collection of key-value pairs
• Records
– heterogeneous aggregate of data
elements indexed by element name
• Design Issues:
1. What is the form of references to
elements?
2. Is the size static or dynamic?
Copyright © 2007 Addison-Wesley. All rights reserved.
1–17
Associative Arrays in Perl
• Names begin with %; literals are
delimited by parentheses
%hi_temps = ("Mon" => 77, "Tue"
=> 79, “Wed” => 65, …);
• Subscripting is done using braces
and keys
$hi_temps{"Wed"} = 83;
– Elements can be removed with delete
delete $hi_temps{"Tue"};