|Think about Loose Coupling|
Have I misunderstood the point of modules or just CPAN?by RAS230 (Acolyte)
|on Oct 24, 2008 at 04:25 UTC||Need Help??|
RAS230 has asked for the wisdom of the Perl Monks concerning the following question:
I've been messing around with perl on and off for a few years now, but never for anything too serious, mostly automating basic sys admin type tasks. I thought modules were mostly for code reuse, and anytime I found myself wanting to add a subroutine to a script that I'd already written for an older script, I'd consider throwing it in a *.pm file.
Now I've got a small handful of *.pm files that each hold several subroutines related to a particular type of task and I use those all the time in my scripts.
If I want to share a handy script with someone else, all I have to do is send them the script and the .pm file(s) it needs or I could take a few seconds to copy the subroutines I need out of the .pm file, paste it into the script itself and modify a line or two so I that can send the whole thing in one file. I thought it was all pretty handy, until I saw CPAN. Now I think I'm doing it wrong.
Sure I'd heard about CPAN, and how it was this great place where people shared all their most useful perl code, but I wasn't really interested in it. I use perl scripts everyday but I don't write new ones all that often. I wanted more experience with the language before I started to mess around with other peoples code. A little bit of "re-inventing the wheel" is great when your learning right?
Recently I've been starting to use perl more and more often, and I've been poking around here, and thought I would finally take a look at some of the modules at CPAN as well to see what I could learn from them. Many of them do look interesting but none of the ones I saw look likely to help me learn perl. It looks like I'd learn more at CPAN as a C programmer. Even the perl scripts on CPAN require modules that were not written in perl.
Why am I compiling perl modules when I can't even compile the scripts that use them? Are all these modules written in other languages because they really cannot be done in perl alone? Where (besides here) is the site where people share useful perl code?
when I consider my own simple (although clearly misguided) setup for reusing and distributing perl, I have to wonder why real perl modules are considered to be such a good idea. I've never had to worry about ppm, dependencies, repositories, or make/compile errors before.
One of the things I love about perl is that I can replace my shell scripts and batch files and use one perl script for both systems. If I wrote a script using one of these modules how could I send it to my friend using windows? I'd have to include a huge set of directions (and probably include a link for nmake) and then hope it (and all it's dependencies) will be supported by the version of activeperl they run. In the past it was as easy as saying "unzip the .pl and .pm file into the same directory".
I really thought *the* website for perl code would be much less complicated.
If I've just got the whole concept of perl modules wrong, what should I be doing with my collection of subroutines?
I was pretty excited about using modules to start getting more out of perl, now I just feel disillusioned and even more unsure of myself.