Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Hello World for module writers

by 2teez (Vicar)
on Aug 31, 2012 at 03:09 UTC ( #990908=note: print w/replies, xml ) Need Help??

in reply to Hello World for module writers


"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 "". ( In my case, I have two namely: "" and "" )
Hello/ 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/ 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 "", 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!:)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://990908]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2020-02-26 07:15 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (113 votes). Check out past polls.