harangzsolt33 has asked for the wisdom of the Perl Monks concerning the following question:
I have a bunch of questions about modules. Feel free to answer any of them or all of them. :)
1. Do I need to put "use strict; use warnings;" at the top of my module? I don't see that in other modules, but why?
2. Should I start the perl module with #!/usr/bin/perl or is it okay to leave this off?
3. I think, I am going to write "use MyPackage;" in my perl program, and then myPackage.pm will be placed in my Perl's INC directory. Is this how it should be done? I mean, it works, but is this standard practice? I've seen some people write "require myPackage" but I don't know if I should use that. The difference between "use" and "require" isn't very clear to me. Since "use" is only 3 letters, that's why I thought I am going to use that one instead. lol
4. I've noticed that some modules have "our $VERSION = ..." but I start my module with "my $VERSION" Is that okay?
5. Btw what's the purpose of the $VERSION string? Is there a part of Perl that will try to access that value at some point during my program's execution?
6. What if my module's name conflicts with another module that exists out there? Let's say I call my module something that does not exist in my INC directory yet, but then someone else also creates a module by the same name and it ends up overwriting my module at some point in the future when I download it? How do I prevent this? I want to create a module name that is short and easy to spell, but the problem is that most of the cool names are already taken.
7. What if my module tries to achieve the same result that another popular module does but mine goes about doing it very differently? How should I name my module? My creativity has evaporated. I don't want to give the same name, because that's confusing. Do I make up a random name that has nothing to do with the program? I could call my module bat or ant or eagle, but that's not very descriptive. Lol
8. Is it important to upload a module to CPAN, or can I just put it on my website and host it there? I know, if I die, my website will probably go offline, and CPAN will outlive me. But I still like my website better, because I have full control over it. The CPAN repository seems so convoluted. It's like a big maze to me.
9. When I open some pm files in the INC directory, I notice that a lot of them seem to have plain text mixed with program code. The text or documentation is preceded by something like "=head1 DESCRIPTION" and I am not sure what this is. Is this standard practice? When I read the perl tutorial, I seem to have skipped this part. I don't remember what the "=" sign does. Is it like /* and */ in C language? Is there a program that makes it easy to read these inline documentations?
10. Is it's okay if I put my documentation on simple comment lines started with "#" instead of "=" ?
So, here is what I have so far:
package MyPackage; $VERSION = "1.00"; my $PRIVATE = 444; # # DESCRIPTION: This function is just a test. # USAGE: myFunc() # sub myFunc { $PRIVATE++; print "\nPackage MyPackage::myFunc(@_)\nPRIVATE = $PRIVATE\n"; } 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Writing my first module
by haukex (Archbishop) on Aug 30, 2023 at 06:58 UTC | |
by harangzsolt33 (Deacon) on Aug 30, 2023 at 09:41 UTC | |
by haukex (Archbishop) on Aug 30, 2023 at 10:53 UTC | |
by eyepopslikeamosquito (Archbishop) on Aug 30, 2023 at 11:06 UTC | |
by Marshall (Canon) on Aug 30, 2023 at 13:17 UTC | |
by harangzsolt33 (Deacon) on Aug 30, 2023 at 14:34 UTC | |
by ForgotPasswordAgain (Vicar) on Aug 30, 2023 at 17:43 UTC | |
Re: Writing my first module
by eyepopslikeamosquito (Archbishop) on Aug 30, 2023 at 07:41 UTC | |
by harangzsolt33 (Deacon) on Aug 30, 2023 at 10:03 UTC | |
Re: Writing my first module
by Discipulus (Canon) on Aug 30, 2023 at 07:39 UTC | |
by harangzsolt33 (Deacon) on Aug 30, 2023 at 10:30 UTC | |
by haukex (Archbishop) on Aug 30, 2023 at 10:52 UTC | |
by Discipulus (Canon) on Aug 30, 2023 at 10:45 UTC | |
Re: Writing my first module
by Marshall (Canon) on Aug 30, 2023 at 06:58 UTC | |
by harangzsolt33 (Deacon) on Aug 30, 2023 at 09:53 UTC | |
Re: Writing my first module
by karlgoethebier (Abbot) on Aug 30, 2023 at 09:01 UTC | |
Re: Writing my first module
by choroba (Cardinal) on Aug 30, 2023 at 22:04 UTC |