I'will follow your advice and try to use my first perl module then!

I understand for the link you gave that in order to use this 'counter.pm' module within my index.pl file i have to use 'use counter.pm' right?

Here is the code i written inside counter.pm

package counter; use strict; my ($db, $pagename, $host) = @_; #======== Insert or Update pagecounter appropriately, then display it +========== eval { # Just ignore errors if the record already exists $db->do('INSERT INTO counters (pagename, pagecounter) VALUES (?, 0) +', undef, $pagename); }; $db->do('UPDATE counters SET pagecounter = pagecounter + 1 WHERE pagen +ame = ?', undef, $pagename) unless( $host eq 'Admin' ); my ($counter) = $db->selectrow_array('SELECT pagecounter FROM counters + WHERE pagename = ?', undef, $pagename);
What i dont know is how to pass the variables $db, $pagename, $host inside the counter.pm module because those 3 variables are a prerequisite for the module to perform its task.

Also the counter.pm module will have to return the variables $counter back to index.pl script so i can print it in the following line of index.pl

Please excuse me as this is the first time im trying to use modules.

ps. Do i need to put the above code in a sub inside counter.pm or creating a sub inside counter.pm isnr neccesary?


In reply to Re^2: How to call counter.pl script from another script by Nik
in thread How to call counter.pl script from another script by Nik

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.