What Is an Expression?

This section describes what is an expression, a mixture of values, variables, operations of expressions and function calls. A tutorial example is provided to show you examples of expressions..

An expression is a mixture of values, operations of expressions and function calls that can be evaluated to a value. Examples of expressions are:

Here is a Perl tutorial script showing you examples of expressions:

#- Expression.pl
#- Copyright (c) HerongYang.com. All Rights Reserved.
#

   print(9.99, "\n");                  # A scalar numeric value

   print("Hello world!", "\n");        # A scalar string value

   print(("PI", 3.14, "Price", 9.99), "\n");
                                       # A list value

   print(undef, "\n");                 # The undef value

   $price = 9.99;
   print($price, "\n");                # A scalar variable

   @links = ("herongyang.com", "perl.org", "cpan.org");
   print(@links, "\n");                # An array variable

   %siteRanks = ("herongyang.com", 4, "perl.org", 6, "google.com", 9);
   print(%siteRanks, "\n");            # A hash variable

   print($price*5, "\n");              # An arithmetic operation

   $name = "Herong";
   print("Hello ".$name, "\n");        # A string concatenation

   $sales = 876.54;
   $expenses = 654.32;
   print($sales>$expenses, "\n");      # A comparison operation

   print(sort(@links), "\n");          # A function call

   print(('Mon','Tue','Wed')[1], "\n");
                                       # A list value subscription

   print($links[1], "\n");             # An array subscription

   print($siteRanks{"herongyang.com"}, "\n");
                                       # A hash subscription

   $capital = 100.00;
   $interest = 0.0475;
   $years = 5;
   print($capital*(1+$interest)**$years, "\n");
                                       # Multiple operations

Here is the output of the tutorial script:

9.99
Hello world!
PI3.14Price9.99

9.99
herongyang.comperl.orgcpan.org
herongyang.com4google.com9perl.org6
49.95
Hello Herong
1
cpan.orgherongyang.comperl.org
Tue
perl.org
4
126.115991387686

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

Expressions, Operations and Simple Statements

What Is an Expression?

 Expression Evaluation Context

 Simple Statements and Modifiers

 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

 Image and Picture Processing

 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

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials

 References

 Full Version in PDF/EPUB