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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |