I have no idea where you got the idea that you needed pointers, but if this is common code, you might want to create a library/module and put the code in there.

For example:

package Mylibrary; use strict; use DBI; my $database="somedb:localhost"; my $username="username"; my $password="password"; sub connect { my $dbh = DBI->connect("DBI:mysql:$database", "$username","$password") or error_fatal("blah"); return $dbh; } sub get_current_vote { my ($dbh) = @_; # if we're not connected (or weren't passed # a connection), connect $dbh ||= connect(); my $sth = $dbh->prepare("SELECT current_vote FROM vote_count;"); $sth->execute() or die $dbh->errstr(); my $current_vote = ($sth->fetchrow_array())[0]; return $current_vote; } 1;
and then you can do the following in your scripts:
# my funky script use strict; use DBI; use Mylibrary; # connect to library: my $dbh = Mylibrary::connect(); # get current vote: my $current_vote = Mylibrary::get_current_vote($dbh);

No need for pointers, and the yucky require can be omitted too. What is more, you've got a ready location for any extra functions you find yourself using in all, or most of your scripts. (You can also export your functions from the Mylibrary namespace, but you can read up on that.)

Hope it helps,
jarich.

Update: Call the file with the Mylibrary package in it Mylibrary.pm, and either store it in the same directory with all the scripts that use it or add a use lib line in your scripts like the following:

# my funky script use strict; use DBI; use lib '/path/to/my/library/'; use Mylibrary;
Note that the use lib line must be before the use Mylibrary line.

In reply to Re: Includes, strict and pointers. by jarich
in thread Includes, strict and pointers. by lagrenouille

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.