Built-in Functions by Category#
The same built-ins as in the alphabetical index, grouped here by problem domain. A function may appear under more than one category: categories are a tag set, not a tree. Every link points at the same detail page regardless of which category the reader arrived through.
SCALARs and strings#
chomp— Strip the trailing input record separator from a string in place.chop— Remove the last character from a string and return it.chr— Return the character whose codepoint is the given number.crypt— One-waypasswd(5)-style hashing of a plaintext string with a salt.fc— Return the Unicode casefolded form of a string for case-insensitive comparison.hex— Interpret a string as a hexadecimal numeral and return its numeric value.index— Find the position of a substring inside a string.lc— Return a lowercased copy of a string.lcfirst— Return a copy of a string with its first character lowercased.length— Return the number of characters in a string.oct— Interpret a string as a number written in octal, hexadecimal, or binary, and return the resulting integer.ord— Return the Unicode code point of the first character of a string.pack— Convert a list of Perl values into a binary string according to a template.q//— Single-quoted string literal with a choice of delimiter.qq//— Build a double-quoted, interpolated string with a delimiter you pick.reverse— Reverse a list — or, in scalar context, reverse the characters of a string.rindex— Find the position of the last occurrence of a substring inside a string.sprintf— Build a formatted string from a format template and a list of values.substr— Extract, replace, or alias a contiguous slice of a string.tr///— Character-by-character substitution.trscans a string and replaces every occurrence of a character fromSEARCHLISTwith the positionally corresponding character fromREPLACEMENTLIST, returning the count of characters it touched.uc— Return an uppercased copy of a string.ucfirst— Return a copy of a string with its first character titlecased.y///— Transliterate characters in a string.y///is a synonym fortr///— the two are identical in every respect.
Regular expressions and pattern matching#
m//— Search a string for a pattern and report whether — and what — it matched.pos— Report or set where the next/gregex match will resume in a string.qr//— Compile a pattern once and hand back a reusable regex object.quotemeta— Return a copy of a string with every regex-significant character backslash-escaped, so the result can be interpolated into a pattern and match its own literal content.s///— Search a string for a pattern and replace every match with a replacement.split— Cut a string into a list of fields using a regex separator.study— A no-op retained for source compatibility with older Perl code.
Numeric functions#
abs— Return the absolute value of a number.atan2— Arc tangent ofY/Xin the range -π to π.cos— Return the cosine of a number given in radians.exp— Raise e to a power.hex— Interpret a string as a hexadecimal numeral and return its numeric value.int— Return the integer portion of a number, truncating toward zero.log— Return the natural logarithm (base e) of a number.oct— Interpret a string as a number written in octal, hexadecimal, or binary, and return the resulting integer.rand— Return a pseudo-random floating-point number in the half-open range[0, EXPR).sin— Return the sine of a number given in radians.sqrt— Return the non-negative square root ofEXPR.srand— Seed the pseudo-random number generator.
Arrays#
each— Step through a hash or array one entry at a time.keys— List all keys of a hash, or all indices of an array.pop— Remove and return the last element of an array.push— Append one or more values to the end of an array.shift— Remove and return the first element of an array.splice— Remove and/or replace a slice of an array in place, and return the removed elements.unshift— Prepend one or more values to the start of an array and return the array’s new length.values— List every value of a hash (or every element of an array).
Lists#
all— Test whetherBLOCKreturns true for every element ofLIST.any— Return true ifBLOCKyields true for at least one element ofLIST.grep— Filter a list to the elements where the block or expression is true.join— Concatenate a list of strings with a separator between each adjacent pair, and return the single resulting string.map— Apply a block or expression to each element of a list and return the flattened results.qw//— Build a list of barewords by splitting a delimited string on whitespace, without quoting or comma-separating each word.reverse— Reverse a list — or, in scalar context, reverse the characters of a string.sort— Sort a list, returning the sorted list.unpack— Extract typed values from a binary or fixed-width string according to a template.
Hashes#
delete— Remove the named key-value pair(s) from a hash, or element(s) from an array, and return what was removed.each— Step through a hash or array one entry at a time.exists— Test whether a hash or array element, or a named subroutine, is present — without creating it and without caring what it holds.keys— List all keys of a hash, or all indices of an array.values— List every value of a hash (or every element of an array).
I/O#
binmode— Set the I/O layer stack on a filehandle — typically to make it deliver raw bytes, or to attach a character encoding.close— Close a filehandle, flush its buffers, and release the underlying file descriptor.dbmclose— Break the binding between a DBM file and a hash previously attached bydbmopen.dbmopen— Bind a DBM file on disk to a hash so hash reads and writes become lookups and stores in the database.die— Raise an exception.eof— Test a filehandle for end-of-file.fileno— Return the OS-level file descriptor number behind a filehandle.flock— Place an advisory lock on an open file.format— Declare a picture-based report template for use bywrite.getc— Read the next single character from a filehandle.print— Write a list of values to a filehandle.printf— Write a formatted string to a filehandle.read— Read a fixed amount of buffered input from a filehandle into a scalar.readdir— Read the next entry, or all remaining entries, from a directory handle opened byopendir.readline— Read one or more records from a filehandle.rewinddir— Reset a directory handle to the start of its listing.say— Print a list of values followed by a newline.seek— Reposition a filehandle for random-access reads or writes.seekdir— Restore a directory handle to a position previously captured bytelldir.select— Either set the default output filehandle, or call theselect(2)syscall for I/O multiplexing. Same name, two unrelated jobs — disambiguated by argument count.syscall— Invoke a raw system call by its kernel number, passing the remaining arguments asintor as a pointer to a string buffer.sysread— Read raw bytes from a filehandle by calling the underlyingread(2)system call.sysseek— Reposition a filehandle at the system level, bypassing PerlIO buffering.syswrite— Write bytes to a filehandle with the rawwrite(2)system call, bypassing Perl’s buffered I/O.tell— Return the current byte position of a filehandle.telldir— Return the current read position of a directory handle as an opaque token.truncate— Shorten (or extend) a file to an exact byte length.warn— Emit a warning toSTDERR.write— Render one record to a filehandle through its associatedformat.
Fixed-length data#
pack— Convert a list of Perl values into a binary string according to a template.read— Read a fixed amount of buffered input from a filehandle into a scalar.syscall— Invoke a raw system call by its kernel number, passing the remaining arguments asintor as a pointer to a string buffer.sysread— Read raw bytes from a filehandle by calling the underlyingread(2)system call.sysseek— Reposition a filehandle at the system level, bypassing PerlIO buffering.syswrite— Write bytes to a filehandle with the rawwrite(2)system call, bypassing Perl’s buffered I/O.unpack— Extract typed values from a binary or fixed-width string according to a template.vec— Read or write a fixed-width slot inside a string treated as a packed bit vector.
Filehandles, files, directories#
chdir— Change the process’s current working directory.chmod— Change the permission bits of a list of files.chown— Change the owner and group of a list of files.chroot— Change the root directory of the current process and every child it later spawns.fcntl— Perform afcntl(2)file-control operation on a filehandle.glob— Expand a shell-style filename pattern into the list of matching paths.ioctl— Perform a device-controlioctl(2)system call on a filehandle.link— Create a hard link fromNEWFILEto the existingOLDFILE.lstat— Return the 13-element status list for a path without following a symbolic link.mkdir— Create a single directory on the filesystem.open— Associate a filehandle with a file, a command, or an in-memory scalar.opendir— Open a directory for reading.readlink— Return the target path a symbolic link points to.rename— Change the name of a file.rmdir— Remove an empty directory.select— Either set the default output filehandle, or call theselect(2)syscall for I/O multiplexing. Same name, two unrelated jobs — disambiguated by argument count.stat— Get a file’s status information.symlink— Create a symbolic link atNEWFILEthat points at the stringOLDFILE.sysopen— Open a file the low-level way, passing an integerMODEbitmask straight through to the underlyingopen(2)system call.umask— Set or read the process file-creation mode mask.unlink— Remove one or more directory entries that name files.utime— Set access and modification times on a list of files.
Control flow#
__FILE__— The name of the source file the token is compiled in.__LINE__— A compile-time token that evaluates to the line number at which it appears in the source.__PACKAGE__— Return the name of the package currently in effect at the point where the token appears.__SUB__— Return a reference to the currently executing subroutine.break— Break out of agivenblock.caller— Return information about the subroutine,eval, orrequirethat called the currently executing code.catch— Handle an exception thrown by a precedingtryblock.continue— Attach a block to a loop that runs after every iteration, just before the condition is re-tested.defer— Schedule a block to run when the enclosing scope exits, for any reason.die— Raise an exception.do— Execute a block of code or run a Perl source file as if it were part of the current program.dump— Cause the running program to produce a core dump immediately.eval— Run a piece of Perl code with any fatal error trapped instead of killing the program.evalbytes— Compile and run a string of Perl source, forcing the source to be interpreted as bytes rather than characters.exit— Terminate the program with a status value.finally— Run cleanup code on the way out of atry/catch, whether the body succeeded, threw, or jumped away.goto— Transfer execution elsewhere in the program without returning.last— Exit a loop immediately, skipping the rest of the body and thecontinueblock.method— Declare a named instance method inside aclassblock.next— Start the next iteration of the enclosing loop immediately.redo— Restart the current iteration of a loop without re-testing the condition and without running thecontinueblock.return— Leave the current subroutine,eval,do FILE,sortblock, or regex eval block, yielding a value to the caller.sub— Declare or define a subroutine.try— Run a block and divert any exception it throws into acatchblock, with an optionalfinallyblock that always runs on the way out.wantarray— Report the calling context of the currently executing subroutine.
Scoping#
caller— Return information about the subroutine,eval, orrequirethat called the currently executing code.class— Declare a namespace that behaves as a native object class.field— Declare a per-instance variable inside aclassblock.import— Populate the caller’s namespace with names a module chooses to export.local— Save the current value of a package variable and restore it when the enclosing scope exits.my— Declare one or more lexically scoped variables.our— Declare a lexically scoped alias to a package variable.package— Declare the compile-time namespace for the declarations that follow.state— Declare a lexically scoped variable whose value persists across calls to its enclosing subroutine.use— Load a module at compile time and import its symbols into the current package.
Misc#
defined— Test whether a value, variable, or subroutine is defined.formline— Format a list of values into a picture string and append the result to the format accumulator$^A.lock— Place an advisory lock on a shared variable, array, hash, or subroutine until the lock goes out of scope.prototype— Return the prototype string of a subroutine, orundefif it has none.reset— Clear every package variable whose name begins with one of a set of letters, and re-arm one-shotm?pattern?matches.scalar— ForceEXPRto be evaluated in scalar context and return its value.undef— The undefined value, and the operator that produces it.
Processes#
alarm— Schedule aSIGALRMto be delivered to the current process after a whole number of wallclock seconds.exec— Abandon this program and run another in the same process.fork— Create a new process running the same program at the same point.getpgrp— Return the POSIX process-group ID that a process belongs to.getppid— Return the process ID of the current process’s parent.getpriority— Return the current scheduling nice value of a process, a process group, or a user.kill— Send a signal to a list of processes.pipe— Open a pair of connected filehandles — one for reading, one for writing.qx//— Run a shell command and capture its standard output.readpipe— Run a shell command and return its standard output.setpgrp— Set the process group of a process.setpriority— Set the scheduling priority (nice value) of a process, process group, or user.sleep— Pause the process for a number of whole seconds.system— Run a separate program and wait for it to finish.times— Report CPU time consumed by this process and its terminated children.wait— Block until any child process exits and reap it.waitpid— Wait for a specific child process to terminate and reap it.
Modules#
do— Execute a block of code or run a Perl source file as if it were part of the current program.import— Populate the caller’s namespace with names a module chooses to export.no— The compile-time inverse ofuse— call a module’sunimportmethod to turn off whatuseturned on.package— Declare the compile-time namespace for the declarations that follow.require— Load a Perl source file at runtime, or demand a minimum Perl version.use— Load a module at compile time and import its symbols into the current package.
Classes and OO#
__CLASS__— Return the class name of the instance currently being acted on.bless— Mark the thing a reference points at as an object in a package.class— Declare a namespace that behaves as a native object class.dbmclose— Break the binding between a DBM file and a hash previously attached bydbmopen.dbmopen— Bind a DBM file on disk to a hash so hash reads and writes become lookups and stores in the database.field— Declare a per-instance variable inside aclassblock.isa— Test whether an object is an instance of a class or of any subclass derived from it.method— Declare a named instance method inside aclassblock.package— Declare the compile-time namespace for the declarations that follow.ref— Return a string describing what a reference points to.tie— Bind a variable to a class so that every access to the variable dispatches through that class’s methods.tied— Return the object backing a tied variable.untie— Break the binding between a variable and its tied class.use— Load a module at compile time and import its symbols into the current package.
Sockets#
accept— Accept an incoming connection on a listening socket.bind— Attach a local address to a socket.connect— Initiate a connection from a socket to a remote address.getpeername— Return the address of the remote end of a connected socket.getsockname— Return the local address of a connected or bound socket.getsockopt— Read one socket option out of the kernel as an opaque packed string.listen— Mark a socket as passive so it can accept incoming connections.recv— Read an incoming message from a socket into a scalar.send— Send a message on a socket.setsockopt— Set a kernel-level option on an open socket.shutdown— Shut down one direction of a socket connection, or both.socket— Create a socket filehandle.socketpair— Create an unnamed, connected pair of sockets that talk to each other.
SysV IPC#
msgctl— Perform a control operation on a System V IPC message queue.msgget— Create or look up a System V IPC message queue and return its id.msgrcv— Receive a message from a System V IPC message queue.msgsnd— Send a message to a System V IPC message queue.semctl— Perform a control operation on a System V semaphore set.semget— Create or look up a System V semaphore set and return its identifier.semop— Perform one or more System V semaphore operations atomically.shmctl— Control or query a System V shared memory segment.shmget— Create or look up a System V shared memory segment and return its identifier.shmread— Copy bytes out of a System V shared memory segment into a Perl scalar.shmwrite— Copy bytes into a System V shared memory segment.
User and group info#
endgrent— Close the group database after iterating it.endpwent— Close the passwd-database iterator opened bygetpwentorsetpwent.getgrent— Read the next entry from the system group database.getgrgid— Look up a group record by numeric group ID.getgrnam— Look up a Unix group by name and return its/etc/grouprecord.getlogin— Return the login name of the user associated with the controlling terminal.getpwent— Return the next entry from the system password database.getpwnam— Look up a user’s passwd record by login name.getpwuid— Look up a user’s passwd record by numeric UID.setgrent— Rewind the group-database iterator back to the first entry.setpwent— Rewind the password-database iterator so the nextgetpwentcall returns the first entry again.
Network info#
endhostent— Close the hosts database after iteration.endnetent— Close the networks database after iteration.endprotoent— Close the protocols database after iteration.endservent— Close the services database after a walk withgetservent.gethostbyaddr— Look up a host record by its packed IP address.gethostbyname— Look up a host record by DNS name.gethostent— Fetch the next entry from the host database.getnetbyaddr— Look up a network record by its numeric network address.getnetbyname— Look up a network record by name.getnetent— Read the next entry from the networks database.getprotobyname— Look up an IP protocol by its textual name and return its database entry.getprotobynumber— Look up a network protocol entry by its assigned protocol number.getprotoent— Fetch the next entry from the protocols database.getservbyname— Look up a network service by its textual name and protocol.getservbyport— Look up a network service by its numeric port and protocol.getservent— Read the next entry from the system services database.sethostent— Open or rewind the hosts database for iteration.setnetent— Open or rewind the networks database for iteration.setprotoent— Open the protocols database and prepare it for sequential reads.setservent— Rewind the services database and optionally keep it open across lookups.
Time#
gmtime— Convert an epoch time to a broken-down UTC time, either as a 9-element list or as actime(3)-style string.localtime— Convert an epoch time to a broken-down calendar time in the local time zone.time— Return the current wall-clock time as an integer number of seconds since the system epoch.times— Report CPU time consumed by this process and its terminated children.