Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

starting perl module

by changma_ha (Sexton)
on Jul 28, 2010 at 12:41 UTC ( [id://851708]=perlquestion: print w/replies, xml ) Need Help??

changma_ha has asked for the wisdom of the Perl Monks concerning the following question:

i have read the tutorial for "Creating Simple Perl Module". And i had practiced few of the simple exercises of creating modules for simple function. I have not started the OOP part yet. i want to know whether the calling a "Subroutine" is same as writing "Function in a module"? and how far can i write complex modules without using OOP concepts?

Replies are listed 'Best First'.
Re: starting perl module
by JavaFan (Canon) on Jul 28, 2010 at 13:10 UTC
    subroutine/function/procedure are (in Perl) all just the same thing. Because the thing is introduced with the keyword sub, the usual term is subroutine. Methods are subroutines as well - in fact, code wise, there's no difference, it's just that they are invoked differently.
    how far can i write complex modules without using OOP concepts
    All the way. There's nothing you can do OO wise you cannot do with non-OO modules. It's just a different style of programming. Use whatever you prefer (this is Perl after all, you can make Perl bend to your wishes instead of the other way around). I've a slight preference of writing OO myself, but I prefer maintaining non-OO code, and vastly prefer documentation of non-OO code over OO code.
Re: starting perl module
by kennethk (Abbot) on Jul 28, 2010 at 13:55 UTC
    First, I would like to second JavaFan's comments above.

    A Perl module that is not designed to be invoked with objects can really be thought of more as a library. I actually use non-OO modules far more often, since my background is Procedural_programming. If you are interested in working with Perl in an object-oriented context, I would suggest reading perlboot and perltoot to understand the mechanics and probably use Moose or Mouse as the framework rather than rolling your own.

    I will assume the tutorial you read was Simple Module Tutorial. With regard to non-OO approaches, I'd recommend reading perlmod. I'd also point out that the examples in Simple Module Tutorial include the pragma vars to declare the variables required by Exporter. As vars states,

    NOTE: For variables in the current package, the functionality provided by this pragma has been superseded by our declarations, available in Perl v5.6.0 or later. See our.

    This means the module at the top of that thread should likely read:

    package MyModule; use strict; use Exporter; our $VERSION = 1.00; our @ISA = qw(Exporter); our @EXPORT = (); our @EXPORT_OK = qw(func1 func2); our %EXPORT_TAGS = ( DEFAULT => [qw(&func1)], Both => [qw(&func1 &func2)]); sub func1 { return reverse @_ } sub func2 { return map{ uc }@_ } 1;
Re: starting perl module
by cdarke (Prior) on Jul 28, 2010 at 14:46 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://851708]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-16 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found