- Example on Parameter List

This section provides a tutorial example on how the parameter list is passed to and received in a user defined subroutine by the local array variable @_.

As mentioned in the previous section, all parameters of a subroutine call are passed as a single list of scalars. If a list (array or hash) is used in a subroutine call as a parameter, it will be exploded into multiple parameters with its elements.

All parameters of subroutine call will be received as elements in a local array variable named as @_.

Here is a tutorial example on parameter list is passed to and received in a subroutine:

#- Copyright (c) All Rights Reserved.
   $a = 3.14;
   @a = ('mon','tue','wed','thu','fri');
   $a{'mon'} = 1;
   $a{'tue'} = 2;
   $a{'wed'} = 3;
sub subParamList {
   print join(',',@_), "\n";

Here is the output of the tutorial script:


The output clearly shows you that array and hash are indeed replaced by their elements as multiple parameters.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

User Defined Subroutines

 Declaring and Calling Subroutines - Example on Parameter List - Example on Parameters as Alias - Example on Return Values - Example on Calling Formats

 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 Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS


 Full Version in PDF/EPUB