Oh OK barking up the wrong tree. Yes it's easy make your script that contains the sub banner_rotator a module. A module is simply perl's version of a library and allows you to call code in one script from another. To make the script with this sub a module follow these easy steps.

1 Add this code at the top of the script after the shebang line:

#!/usr/bin/perl

package Mysubs; # this allows us to identify this package

You can pick any name you want but usually you would use the same name as the script.

2 Change the name of the script to say Mysubs.pm. The name does not matter but the script needs to end with a .pm suffix. You can use a sym link to ensure that this does not break anything to link the old and new names. Alternatively you can use a 'require Mysubs.pl' as noted below if you don't want to change the name/use a symlink.

3 Finally a module must return true. To make sure your new module returns true place this at the end of it:

1;

Yup, that's it, just add a 1.

OK you are now the proud owner of a perl module! Now to use the banner_rotator sub from your SSI script all you need to do is this:

#!/usr/bin/perl # you may need to do this: BEGIN{push @INC, "/path/to/mysubs/module"} # so that Perl can find your module when you do this: use Mysubs; # you can now call banner_rotator sub (or any sub) like this: &Mysubs::banner_rotator;

Notes @INC tells Perl where to look for modules - it is effectively Perl's PATH variable for module lookups. To save explaining about where/why/how perl will look just tell it as shown! The use Mysubs; tells perl to use the first perl script called 'Mysubs.pm' it finds when searching the directories in @INC. It is also possible to require 'Mysubs.pl'; and avoid the name change to a .pm suffix if you want. The &Mysubs:: part before banner_rotator tells perl to look for this sub in the Mysubs package (it is easiest to call the module and package to same to save confusion here).

Hope this helps. Let me know if you have any problems. If you get a login you can /msg me directly :-)

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Calling a subroutine and dispalying an image using ssi by tachyon
in thread Calling a subroutine and dispalying an image using ssi by ginocapelli

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.