Hi,
"I am trying to produce a Perl module. "Hello World" is escaping me..." HOW?
"... if there was a Hello::World module..."
Really, why would anyone want to write "Hello, World" as a module?
When such task can be achieved in a one-liner as shown previously. However, who knows? To the longings of the heart, who can tell?
Below is a head up.
If you want to produce a module Hello::World, create a folder called Hello, and then inside the folder make a perl module named "World.pm". ( In my case, I have two namely: "World.pm" and "World2.pm" )
Hello/World.pm contains the following lines:
package Hello::World;
use warnings;
use strict;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(greetings);
sub greetings {
return "Hello, World";
}
1;
You can even decide to go the OOP way like so:
Hello/World2.pm contains the following lines:
package Hello::World2;
use warnings;
use strict;
sub new {
my $class = shift;
my $self = { greeting => shift, };
return bless $self, $class;
}
sub the_greetings {
my $self = shift;
return $self->{greeting};
}
1;
Make another perl file, say "hello.pl", then use Hello::World therein like so:
#!/usr/bin/perl
use warnings;
use strict;
use Hello::World;
use Hello::World2; ## OOP
print greetings(); ## prints Hello, World
print $/;
my $greet = Hello::World2->new("Hello, World, Again");
print $greet->the_greetings(); ## prints Hello, World, Again
You can get more info. from
perlmod,
perlmodlib and several other books and tutorials onlines.
I can only hope this turn on the bulb!:)