print - perldoc.perl.org

Perl Programming Documentation
Download Perl
Explore

Manual

- Overview
- Tutorials
- FAQs
- History / Changes
- License

Reference

- Language
- Functions
- Operators
- Special Variables
- Pragmas
- Utilities
- Internals
- Platform Specific

Modules

- A • B • C • D • E
- F • G • H • I • L
- M • N • O • P • S
- T • U • X

Tools

- Preferences

# print

Perl 5 version 12.2 documentation
Go to top
Show recent pages
Recently read

# print

Perl functions A-Z | Perl functions by category | The 'perlfunc' manpage

- print FILEHANDLE LIST

- print LIST
- print

  Prints a string or a list of strings. Returns true if successful. FILEHANDLE may be a scalar variable containing the name of or a reference to the filehandle, thus introducing one level of indirection. (NOTE: If FILEHANDLE is a variable and the next token is a term, it may be misinterpreted as an operator unless you interpose a `+` or put parentheses around the arguments.) If FILEHANDLE is omitted, prints to standard output by default, or to the last selected output channel; see select. If LIST is also omitted, prints `$_` to the currently selected output handle. To set the default output handle to something other than STDOUT use the select operation. The current value of `$,` (if any) is printed between each LIST item. The current value of `$\` (if any) is printed after the entire LIST has been printed. Because print takes a LIST, anything in the LIST is evaluated in list context, and any subroutine that you call will have one or more of its expressions evaluated in list context. Also be careful not to follow the print keyword with a left parenthesis unless you want the corresponding right parenthesis to terminate the arguments to the print; put parentheses around all the arguments (or interpose a `+` , but that doesn't look as good).

  Note that if you're storing FILEHANDLEs in an array, or if you're using any other expression more complex than a scalar variable to retrieve it, you will have to use a block returning the filehandle value instead:

          print { $files[$i] } "stuff\n";    print { $OK ? STDOUT : STDERR } "stuff\n";

  Printing to a closed pipe or socket will generate a SIGPIPE signal. See perlipc for more on signal handling.