i've had this little, meandering thought, so i thought, i'd just toss it out here.

up 'til now, (being a newbie,) i've been writing my code directly -> not using any modules. But in looking thru the SOPW, many questions involved the use of these modules, and it seems like every monk uses them regularly.

now, i know, that perl-programmers love short code. The less writing, the better. I know, that modules are used to avoid 'reinventing the wheel', as they say - as well as importing complex and long lines of code into a script by using but a few words.

so, i was surprised to find, that some of the most popular uses of these modules, requires the same amount of code or more - to call it - than just to simply write it out yourself.

an example (based on an example from CGI Programming with Perl pg 287 / O'Reilly):

example#1: CGI.pm ~

my $cookie = $q->cookie( -name => "cart_id", -value => 12345, -domain => ".oreilly.com", -expires => "+1y", -path => "/cgi", -secure => 1 ); print "Set-Cookie: $cookie\n";

example#2: normal (inline) synatx ~

print "Set-Cookie: cart_id=12345; domain=".oreilly.com"; path=/cgi; ex +pires=+1d; secure\n";

CGI.pm looks a tad longer.

But even if they were equal in length - isn't it better to do #2 and incorporate this directing into your script, rather than #1, which requires perl to do a whole other set of routines/processes (opening CGI.pm, looking for the code, resolving any variables there, and merging it into the 'main' script to arrive at the same result.) ...?

does it make that much difference or am i splitting hairs?

20040322 Edit by BazB: Changed title from 'To Import or Not To Import'


In reply to When to use modules? by wolfi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.