Getting Started
Introduction
Perl IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Top Sites
More Tutorials
Books
Magazines
Articles
NewsLetters
Mailing Lists
NewsGroups
Forums
User Groups
Talk Shows
Blogs
Clothing

GBIC >> Perl >> Information Center Tutorials >> Printing

Perl Information Center Tutorials - Printing
These tutorials were written to help you get a quick, but thorough, understanding of Perl - the scope of the language as well as it's specific capabilities.

Beginners Built-In Functions     Advanced CGI Applications

Printing
Perl provides only a limited number of print functions, but has strong formatting features.

    • Unformatted    
     print
    • Formatted
     printf 

Print Functions Reference
Here's a quick reference of the available print functions, in alphabetical order.

Unless otherwise noted, these functions operate on $_ by default.

  • print - output a list to a filehandle
        print FILEHANDLE LIST     # no comma between arguments
    
        print <OUTFILE>> $number  # print value of $number to file
        print $number             # default is to standard output
    
        
  • printf - output a formatted list to a filehandle
        printf FILEHANDLE FORMAT, LIST
    
        printf <OUTFILE> "%08d", $number;   # up to 8 leading zeros
        printf "%.3f", $number;             # rounded
        

Format Strings
Format control strings (for use with the printf function) are created using combinations of elements from the the following 3 tables.

    List Element Formats
  • %s - string
  • %d - signed integer
  • %i - same as %d
  • %u - unsigned integer
  • %o - unsigned octal integer
  • %x - unsigned hex integer
  • %X - same as %x, but with use uppercase letters
  • %e - floating point number, scientific notation
  • %E - same as %e, but with uppercase "E"
  • %f - floating point number, in fixed decimal notation
  • %F - same as %f
  • %g - floating point number, %e of %f notation chosen by Perl
  • %G - sames as %g, but with uppercase "E"
  • %c - ASCII character of value in format list
    Widths
  • number - minimum field width
  • .number - digits after decimal point, max string length, min integer length
  • * - same as number but value is read in from list of data to be output
  • .* - same as .number but value read in from list of data to be output
    Format Flags
  • space - place spaces before number (default)
  • 0 - place zeros before number
  • + - put a + or - before number
  • - - left justify
  • # - prefix octal with "0,", hex with "0x"

If you have any suggestions or corrections, please let me know.