bubnoff has asked for the wisdom of the Perl Monks concerning the following question:
I have a class called book.pm with an attribute called 'html'. This attribute is a file which I want to write to. Book.pm uses a package called template.pm to help it write the html. I cannot seem to pass the book->html attribute to template. I get no complaints and the code runs, but I get files written in the scripts directory. Maybe a bit o' code will help clarify.
Here's an excerpt from book.pm:sub new { my ($class) = @_; #call the constructor of the parent class, Person. my $self = $class->SUPER::new(); $self->{_name} = undef; $self->{_template} = undef; $self->{_html} = undef; bless $self, $class; return $self; } sub html{ my ( $self, $html ) = @_; $self->{_html} = $html if defined($html); return ( $self->{_html} ); }
Later I try to toss the file to Template to build the actual page like so:
my $template = eval { new Template(); } or die ($@); $template->header($html, $header, $time);
Here's the corresponding Template.pm bit:
sub header { my $html = shift; my $header = shift; my $time = shift; open (OUT,">$html") or die ("No html file: $!\n");
It's writing to text files and html files, but not the one that's passed. A sample html file is entitled:
Template=HASH(0x81eb334)
Also, if I define it directly in Template then how do I access it with the other
variables I pass to it. Where is it in the stack, so to speak?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing variable to method in perl
by Tanktalus (Canon) on Aug 21, 2009 at 02:06 UTC | |
by bubnoff (Novice) on Aug 21, 2009 at 02:23 UTC |