Scalar Value Interpretation

This section describes how a scalar value will be interpreted in an operation. A tutorial example is provided to verify scalar value interpretation rules.

When a scalar value is used in an operation, it could be interpreted in three ways depending on the type of value the operation is expecting:

To verify the rules listed above, I wrote the following Perl tutorial script:

#- ScalarValue.pl
#- Copyright (c) 1995 by Dr. Herong Yang, http://www.herongyang.com/
#
   print(0.00, "\n");                  # 0
   print(00.00, "\n");                 # 00
   print(1e-1, "\n");                  # 0.1
   print(1e+50, "\n");                 # 1e+050
   print(1e+100, "\n");                # 1e+100
   print(1e+1000, "\n");               # 1.#INF
   print(1e+1000 + 1, "\n");           # 1.#INF
   print('1e+1000' + 1, "\n");         # 1.#INF
   print(0.1234567890123456789, "\n"); # 0.123456789012346
   print(1 / 3, "\n");                 # 0.333333333333333
   print(1 / '3', "\n");               # 0.333333333333333
   print(1 + 3, "\n");                 # 4                
   print(1.3, "\n");                   # 1.3              
   print(1 . 3, "\n");                 # 13               
   print((1 . 3) * 5, "\n");           # 65               
   print('Hello '. 'world!', "\n");    # Hello world!     
   print(1 + 'a', "\n");               # 1                
   print(1 * 'a', "\n");               # 0                
   print(1 + '', "\n");                # 1                
   print('FALSE', "\n") if (not 0);    # FALSE            
   print('FALSE', "\n") if (not '0');  # FALSE            
   print('FALSE', "\n") if (not '');   # FALSE            
   print('TURE', "\n") if (' ');       # TURE             
   print('TURE', "\n") if (1);         # TURE             

The printed values are entered into the script as comments. You are probably surprised to see some of the printed values. Me too.

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