Полезная информация

Advanced Perl Programming

Advanced Perl ProgrammingSearch this book
Previous: 1.3 Nested Data StructuresChapter 1
Data References and Anonymous Storage
Next: 1.5 Symbolic References
 

1.4 Querying a Reference

The ref function queries a scalar to see whether it contains a reference and, if so, what type of data it is pointing to. ref returns false (a Boolean value, not a string) if its argument contains a number or a string; and if it's a reference, ref returns one of these strings to describe the data being referred to: "SCALAR", "HASH", "ARRAY", "REF" (referring to another reference variable), "GLOB" (referring to a typeglob), "CODE" (referring to a subroutine), or "package name " (an object belonging to this package - we'll see more of it later).

$a = 10;
$ra = \$a;

ref($a) yields FALSE, since $a is not a reference.

ref($ra) returns the string "SCALAR", since $ra is pointing to a scalar value.


Previous: 1.3 Nested Data StructuresAdvanced Perl ProgrammingNext: 1.5 Symbolic References
1.3 Nested Data StructuresBook Index1.5 Symbolic References