Questions And Answers

More Tutorials

Files Formats


Perl has a fairly sophisticated mechanism for generating formatted output. This involves using pictorial representations of the output, called templates, and the function write.
Using a format consists of three operations:
1. Defining the format (template)
2. Loading data to be printed into the variable portions of the format
3. Invoking the format.

Format templates have the following general form:
$value_one, $value_two, …

Everything between the “=” and the “.” is considered part of the format and everything (in the fieldlines) will be printed exactly as it appears (whitespace counts). Fieldlines permit variable interpolation via fieldholders:
Hi, my name is @<<<<<, and I’m @< years old

$name, $age 

Fieldholders generally begin with a @ and consist of characters indicated alignment/type.

The name of the format corresponds to the name of a filehandle. If write is invoked on a filehandle, then the corresponding format is used. Naturally then, if you’re printing to standard output, then your format name should be STDOUT. If you want to use a format with a name other than that of your desired filehandle, set the $~ variable to the format

There are special formats which are printed at the top of the page. If the active format name is FNAME, then the “top” format name is FNAME_TOP. The special variable $% keeps a count of how many times the “top” format has been called and can be used to number pages.


In this page (written and validated by ) you learned about Perl Files format . What's Next? If you are interested in completing Perl tutorial, your next topic will be learning about: Perl Manipulating files and directories.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.