![]() |
Printing Revisited![]() ![]() ![]() ![]() ![]()
We've been using the print() function throughout this book without really looking at how it works. Let's remedy that now. The print() function is used to send output to a file handle. Most of the time, we've been using STDOUT as the file handle. Because STDOUT is the default, we did not need to specify it. The syntax for the print() function is:
Perl also has the printf() function which lets you be more precise in how things are printed out. The syntax for printf() looks like this. printf FILE-HANDLE (FORMAT-STRING, LIST) Like print(), the default file handle is STDOUT. The FORMAT-STRING parameter controls what is printed and how it looks.
Format Specifiers for the printf() Function
Forces the value to be at least a certain width. For example, %10.3f means that the value will be at least 10 positions wide. And because f is used for floating point, at most 3 positions to the right of the decimal point will be displayed. %.10s will print a string at most 10 characters long. print("This is line I.In"); select($oldHandle); # restore the old file handle print("This is line 2.\n"); This program displays: This is line 2. and creates the TESTFILE.DAT file with a single line in It: This is line 1. Perl also has the printf() function which lets you be more precise in how things are printed out. The syntax for printf() looks like this.printf FILE-HANDLE (FORMAT-STRING, LIST) Like print(), the default file handle is STDOUT. The FORMAT-STRING parameter controls what is printed and how it looks. Format Specifiers for the printf() Function Specifier Description Indicates that a single character should be printed. Indicates that a string should be printed. Indicates that a decimal number should be printed. Indicates that an unsigned decimal number should be printed. Indicates that a hexadecimal number should be printed. Indicates that an octal number should be printed. Indicates that a floating point number should be printed in scientific notation. Indicates that a floating point number should be printed. Indicates that a floating point number should be printed using the most space-spacing format, either e or f. Format Modifiers for the printf() Function Modifier Description - Indicates that the value should be printed left-justified. Forces octal numbers to be printed with a leading zero.
|
|
PERL Perl Program Data Types Types of Variables Operator Types Functions String Functions Array Functions Expressions Statement Blocks The if Statement Unless Statement While Loops Until Loop For Loop Foreach Loop Jump Keywords Subroutines Perl References Die Function Exit Function Localtime Function Standard Files File Test Operators File Functions Opening Files Reading into Hash Printing Revisited Globbing Splitting a Record into Fields Perl's Special Variables Regular Expression Simple True-False Searches Inexact Matches in Regular Expressions Matching Any Character Characters with Class Special Locations Quantifiers Greedy Matching Modifiers Localtime Function Subsituations Letter for Letter Translations Generating A Simple Report Defining a Report Template Specifying the Picture Line Specifying the Argument Line Adding a Header Writing the ReportDomain Names Home Importance of a domain name How does a web domain name work? Domain name syntax Choosing a domain name Domain Transfer Domain Parking IP AddressWeb Design HTML DHTML XML JAVASCRIPT VBSCRIPT PHOTOSHOPWeb Hosting Web Server Web Server Software Microsoft Internet Information Server Web hosting ISP Shared web hosting Virtual web hosting Dedicated web hosting Web hosting colocation Managed web hostingE Commerce Principles of E-Commerce E-Banking Electronic Payment System E-Security Credit Cards Smart Cards
The Mailbox POP Server SMTP Server IMAP Protocol |
| Home | Web Hosting | Web Design | Sitemap |
| Copyright (C) 2007. Web Domain design hosting. All rights reserved. |