The typeglob is a composite data type that contains one instance of each other data types. It is an amalgam of all Perl’s data types, from which it gets its name. It is a sort of ‘super reference’ whose value is not a single reference to something but six slots that can contain six different references, all at once:
a.scalar – A reference to scalar
b.array – A reference to array
c.hash – A reference to hash
d.code – A reference to a subroutine
e.handle – A file or directory handle
f.format – A format definition
Defining Typeglobs:
$message = “Some text”;
*missive = *message;
print $missive; # prints “some text”;
or
*glob = \$scalar;
*glob = \@arr;
*glob = \%hash;
*glob = sub { return “\n Try this !” };
Manipulating Typeglobs:
print “\n $glob “;
print “\n @glob ”;
foreach $key (keys %glob)
{
print “\n $key => $glob{$key} “;
}
print glob();
Accessing Typeglobs:
$scalarref = *glob{SCALAR};
$arrayref = *glob{ARRAY};
$hashref = *glob{HASH};
$subref = *glob{CODE};
Tuesday, March 3, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment