Variables - Scalar, Array and Hash

This section describes Perl variable types: Scalar, Array, and Hash. Variable names must be prefixed with special symbols to indicate their types, $, @ and %.

Perl supports 3 types of variables: Scalar, Array, and Hash.

1. Scalar Variable - A variable to hold a scalar value. The name of a scalar variable must be prefixed with the dollar sign, $, and followed by an identifier, $identifier. For example: $price and $url.

2. Array Variable - A variable to hold a list value. The name of an array variable must be prefixed with the at sign, @, and followed by an identifier, @identifier. For example: @orders and @links.

3. Hash Variable - A variable to hold an associative array, which is a special list value - members are grouped as pairs of keys and values. The name of an array variable must be prefixed with the percent sign, %, and followed by an identifier, %identifier. For example: %priceList and %siteRanks.

Like in many other programming languages, a variable name identifier in Perl is a string beginning with a letter or underscore, and containing letters, underscores, and digits.

Variables for different data types are in different name spaces. You could use the same variable identifier for a scalar, an array, and a hash.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

Data Types: Values and Variables

 Scalar Values and List Values

 Scalar Value Constructors

 Scalar Value Interpretation

 List Value Constructors

Variables - Scalar, Array and Hash

 Using Scalar Variables

 Using Array Variables

 Using Hash Variables

 "undef" Value and Undefined Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Converting Perl Script to Executable Binary

 Using DBM Database Files

 Using MySQL Database Server

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server

 CGI.pm Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 References

 PDF Printing Version