G
Gary Schenk
Exercise 6.8 of "Perl How to Program" asks the student to create
a simple module to use in making a web page. I've failed
miserably at this, and don't know why. The subroutines work when
they are in the source file, but when I call them from a
package, they return an error.
I've gone to learn.perl.org for examples of return statements and
mine seem to be OK. I'm using fully qualified names properly, I
believe. The llama book doesn't go into this deeply, and the
camel book makes my head hurt.
Hopefully someone will spot my error right away. I do appreciate
any help. Here is the source file:
#################################
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
use MINE;
print "Create a simple webpage using my HTML package.\n";
my $start = MINE::start_document();
my $para = MINE::create_paragraph();
my $ending = MINE::end_document();
open( WEB, ">web.html" ) or die("Can't open a new file: $!" );
print( WEB "$start $para $ending");
close WEB;
#####################################
Here is the module MINE.pm:
#####################################
#!/usr/bin/perl
package HTML;
sub start_document
{
print "Enter the title of your webpage: ";
chomp( my $title = <STDIN> );
my $start_statement =
"<html><head><title>$title</title></head><body>\n";
return $start_statement;
}
sub create_paragraph
{
print "Enter a string for a paragraph: ";
chomp( my $string = <STDIN> );
my $para_statement = "<p>$string</p>";
return $para_statement;
}
sub end_document
{
my $end_statement = "</body></html>\n";
return $end_statment;
}
########################################
Here is the error:
-bash-2.05b$ ./web.pl
MINE.pm did not return a true value at ./web.pl line 6.
BEGIN failed--compilation aborted at ./web.pl line 6 (#1)
(F) A required (or used) file must return a true value to
indicate that
it compiled correctly and ran its initialization code
correctly. It's
traditional to end such a file with a "1;", though any true
value would
do. See perlfunc/require.
Uncaught exception from user code:
MINE.pm did not return a true value at ./web.pl line 6.
BEGIN failed--compilation aborted at ./web.pl line 6.
a simple module to use in making a web page. I've failed
miserably at this, and don't know why. The subroutines work when
they are in the source file, but when I call them from a
package, they return an error.
I've gone to learn.perl.org for examples of return statements and
mine seem to be OK. I'm using fully qualified names properly, I
believe. The llama book doesn't go into this deeply, and the
camel book makes my head hurt.
Hopefully someone will spot my error right away. I do appreciate
any help. Here is the source file:
#################################
#!/usr/bin/perl
use warnings;
use strict;
use diagnostics;
use MINE;
print "Create a simple webpage using my HTML package.\n";
my $start = MINE::start_document();
my $para = MINE::create_paragraph();
my $ending = MINE::end_document();
open( WEB, ">web.html" ) or die("Can't open a new file: $!" );
print( WEB "$start $para $ending");
close WEB;
#####################################
Here is the module MINE.pm:
#####################################
#!/usr/bin/perl
package HTML;
sub start_document
{
print "Enter the title of your webpage: ";
chomp( my $title = <STDIN> );
my $start_statement =
"<html><head><title>$title</title></head><body>\n";
return $start_statement;
}
sub create_paragraph
{
print "Enter a string for a paragraph: ";
chomp( my $string = <STDIN> );
my $para_statement = "<p>$string</p>";
return $para_statement;
}
sub end_document
{
my $end_statement = "</body></html>\n";
return $end_statment;
}
########################################
Here is the error:
-bash-2.05b$ ./web.pl
MINE.pm did not return a true value at ./web.pl line 6.
BEGIN failed--compilation aborted at ./web.pl line 6 (#1)
(F) A required (or used) file must return a true value to
indicate that
it compiled correctly and ran its initialization code
correctly. It's
traditional to end such a file with a "1;", though any true
value would
do. See perlfunc/require.
Uncaught exception from user code:
MINE.pm did not return a true value at ./web.pl line 6.
BEGIN failed--compilation aborted at ./web.pl line 6.