in reply to Calling a subroutine and dispalying an image using ssi
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
|
|---|