S
simulant
I am using the `format` command in a reporting module I am writing, and
I want to be able to store multiple format pictures in files and then
load the needed format from the file. This would be an example session
using my modules:
$rpt = new Report();
$rpt->title("My Title");
$rpt->formattop("header1.fmt"); # there would be multiple headers to
choose from
$rpt->format("format1.fmt"); # format1.fmt would be stored in
/usr/lib/perl/formats, for instance
$rpt->run(); # generate the content of the report
$rpt->write("report.out"); # this writes the output using the format
specified in 'format1.fmt'
header1.fmt:
Title: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$title
Date: @>>>>>>>>>>>>>>>>>>>
$now
..
format1.fmt:
@*
$content
..
The Report module would look like this:
package Report;
sub new {
# code for constructor ...
}
sub title {
# code to set title
}
sub format {
# code to set format variable
}
sub run {
# this sets the content of the report
}
# arg to write is filename (report.out)
sub write {
<b># this is where I need help!!</b>
my $self = shift;
open ($self->format, ">", shift);
$title = $self->title;
$now = $self->getDateTime;
$content = $self->run;
write $self->format;
close $self->format;
}
Nowhere in perlform or anywhere else I searched was there a mention of
how to load formats from files. The code above in the write sub does
NOT work, but I would like to do something similar.
I have the formats defined at the top of the module for now, and this
works, but this does not support dynamically loading different formats:
format FORMAT1_TOP =
Title: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$title
Date: @>>>>>>>>>>>>>>>>>>>
$now
..
format FORMAT1 =
@*
$content
..
I want to be able to store multiple format pictures in files and then
load the needed format from the file. This would be an example session
using my modules:
$rpt = new Report();
$rpt->title("My Title");
$rpt->formattop("header1.fmt"); # there would be multiple headers to
choose from
$rpt->format("format1.fmt"); # format1.fmt would be stored in
/usr/lib/perl/formats, for instance
$rpt->run(); # generate the content of the report
$rpt->write("report.out"); # this writes the output using the format
specified in 'format1.fmt'
header1.fmt:
Title: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$title
Date: @>>>>>>>>>>>>>>>>>>>
$now
..
format1.fmt:
@*
$content
..
The Report module would look like this:
package Report;
sub new {
# code for constructor ...
}
sub title {
# code to set title
}
sub format {
# code to set format variable
}
sub run {
# this sets the content of the report
}
# arg to write is filename (report.out)
sub write {
<b># this is where I need help!!</b>
my $self = shift;
open ($self->format, ">", shift);
$title = $self->title;
$now = $self->getDateTime;
$content = $self->run;
write $self->format;
close $self->format;
}
Nowhere in perlform or anywhere else I searched was there a mention of
how to load formats from files. The code above in the write sub does
NOT work, but I would like to do something similar.
I have the formats defined at the top of the module for now, and this
works, but this does not support dynamically loading different formats:
format FORMAT1_TOP =
Title: @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$title
Date: @>>>>>>>>>>>>>>>>>>>
$now
..
format FORMAT1 =
@*
$content
..