How to Create Reports With Perl
Use Perl to create simple reports. Include a header with a title, page number and other important information. Perl tracks how many lines are in the report and makes a new page when needed. These reports are useful for reporting lots of data with a small text output. Create the reports using a free-form report or set a fixed format.
Instructions
-
-
1
Open your Perl application FORMAT.DAT file.
-
2
Enter open "(FILE, "
@lines = ;
close(FILE);." This sets the format for the report so that each entry is its own line. -
-
3
Create the body of the Perl reports by giving Perl direction on what to report. Using a grocery list as an example, enter
"for each (@lines) {
chop;
($isle, $item, $price) = (split(/!/));
print("Isle=$isle Item=$item Price=$price\n");
}" -
4
Use this format if the database items are all complete. If there are items missing, the format won't account for the missing items. See the example:
Isle=5 Item= Price=
Isle=2 Item=Oranges Price=0.32
Isle=7 Item=Potato Chips Price=2.95
Isle=9 Item=Light Bulbs Price=2.50 -
5
Write the list another way if you want a fixed-width format. Use the code
"for each (@lines) {chop;
($isle, $item, $price) = (split(/!/));
$isle = "" if !defined($isle); These lines assign null
$item = "" if !defined($item); strings if no info is
$price = "" if !defined($price); present in the record.
print("Isle=$isle Item=$item Price=$price\n");
}"
-
6
Output the created Perl reports similar to the following example:
Isle=5 Item= Price=
Isle=2 Item=Oranges Price=0.32
Isle=7 Item=Potato Chips Price=2.95
Isle=9 Item=Light Bulbs Price=2.50
-
1
Resources
Comments
-
Tonyclav
Aug 28, 2008
Perl has a 'format' command which can be used to make sure report fields are aligned and formatted (e.g. as currency) correctly. -
Tonyclav
Aug 28, 2008
Perl has a 'format' command which can be used to make sure report fields are aligned and formatted (e.g. as currency) correctly.