Skip to Main Content
Perl in a Nutshell, 2nd Edition
book

Perl in a Nutshell, 2nd Edition

by Nathan Patwardhan, Ellen Siever, Stephen Spainhour
June 2002
Beginner content levelBeginner
759 pages
80h 42m
English
O'Reilly Media, Inc.
Content preview from Perl in a Nutshell, 2nd Edition

Chapter 5. Function Reference

This chapter gives a brief description of Perl’s built-in functions. Each description gives the syntax of the function, with the types and order of its arguments .

Required arguments are shown in italics, separated by commas. If an argument must be a specific variable type, that variable’s identifier will be used (e.g., a percent sign for a hash, % hash). Optional arguments are placed in brackets. Do not use the brackets in function calls unless you really want to use an anonymous hash reference.

There are different ways to use a built-in function. For starters, any argument that requires a scalar value can be made up of any expression that returns one. For example, you can obtain the square root of the first value in an array:

$root = sqrt (shift @numbers);

shift removes the first element of @numbers and returns it to be used by sqrt.

Many functions take a list of scalars for arguments. Any array variable or other expression that returns a list can be used for all or part of the arguments. For example:

chmod (split /,/ FILELIST>); # An expression returns a list
chmod 0755, @executables;    # Array used for part of arguments

In the first line, the split expression reads a string from a filehandle and splits it into a list. The list provides proper arguments for chmod. The second line uses an array that contains a list of filenames for chmod to act upon.

Parentheses are not required around a function’s arguments. However, without parentheses, functions are viewed ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl by Example, Fourth Edition

Perl by Example, Fourth Edition

Ellie Quigley
Perl Cookbook, 2nd Edition

Perl Cookbook, 2nd Edition

Tom Christiansen, Nathan Torkington
Perl in a Nutshell

Perl in a Nutshell

Nathan Patwardhan, Ellen Siever, Stephen Spainhour
Learning Perl, 7th Edition

Learning Perl, 7th Edition

Randal L. Schwartz, brian d foy, Tom Phoenix

Publisher Resources

ISBN: 0596002416Errata Page