my $fmt = "%-13s % 24f %-24f %-4s\n"
. " %38.6f %-14f %-4s\n";
####
my $fmt = "%-13s % 24f %-14f %-4s\n"
. "%-13s %24.6f %-14f %-4s\n";
. . . .
printf $fmt, 'MM_STD_gate', 152.401574, -22.047244, 'mils',
'', 3871.0, -560.0, 'microns';
####
Roboticus@Waubli ~
$ cat t.pl
use strict;
use warnings;
# The data
my @recs = (
[ 'MM_MM_STD_gate', 152.401574, -22.047244, 'mils',
3871.0, -560.0, 'microns' ],
[ 'RFN_a', 337.244094, 0.787402, 'mils',
8566.0, 20.0, 'microns' ],
[ 'RFN_b', 366.181102, 0.787402, 'mils',
9301.0, 20.0, 'microns' ],
[ 'RFN_c', 376.929133, 0.787402, 'mils',
9574.0, 20.0, 'microns' ],
[ 'MM_STD2_gate', -259.488188, -22.047244, 'mils',
-6591.0, -560.0, 'microns' ],
[ 'RBASE_right_2', -366.181102, -33.464566, 'mils',
-9301.0, -850.0, 'microns' ],
);
print "\n------ Report1: (printf) ------\n\n";
# I made it easy on myself by *not* using the fake field here so I could
# just print the data by expanding the data in-line in the printf statement.
my $fmt = "%-13s % 24f %-14f %-4s\n"
. " %24.6f %-14f %-4s\n";
for my $ar (@recs) {
printf $fmt, @$ar;
}
print "\n\n------ Report 2 (Named formats) ------\n\n";
# The format statement embeds the variables to map to the fields inline, so
# the variable must already be declared
my $ar;
# Define the format visually, along with the variables to stuff into them
format DETAIL =
@<<<<<<<<<<<< @####.##### @###.###### @<<<<<<<<<
$ar->[0], $ar->[1], $ar->[2], $ar->[3],
@####.##### @###.###### @<<<<<<<<<
$ar->[4], $ar->[5], $ar->[6];
.
# Specify the format type to use for each write statement (you can have
# multiple formats and switch between them as needed).
select(STDOUT);
$~ = "DETAIL";
# Print the report
for $ar (@recs) {
write;
}
Roboticus@Waubli ~
$ perl t.pl
------ Report1: (printf) ------
MM_MM_STD_gate 152.401574 -22.047244 mils
3871.000000 -560.000000 microns
RFN_a 337.244094 0.787402 mils
8566.000000 20.000000 microns
RFN_b 366.181102 0.787402 mils
9301.000000 20.000000 microns
RFN_c 376.929133 0.787402 mils
9574.000000 20.000000 microns
MM_STD2_gate -259.488188 -22.047244 mils
-6591.000000 -560.000000 microns
RBASE_right_2 -366.181102 -33.464566 mils
-9301.000000 -850.000000 microns
------ Report 2 (Named formats) ------
MM_MM_STD_gat 152.40157 -22.047244 mils
3871.00000 -560.000000 microns
RFN_a 337.24409 0.787402 mils
8566.00000 20.000000 microns
RFN_b 366.18110 0.787402 mils
9301.00000 20.000000 microns
RFN_c 376.92913 0.787402 mils
9574.00000 20.000000 microns
MM_STD2_gate -259.48819 -22.047244 mils
-6591.00000 -560.000000 microns
RBASE_right_2 -366.18110 -33.464566 mils
-9301.00000 -850.000000 microns