J9 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get my head around creating my own module. I have got the following out of the Perl Cookbook and am having some difficulties. I have gone through SuperSearch but have not been able to find my answers
Given the following module which I called Test.pm and located in the c:/perl/site/lib dir ...I am using the following code to try and call a subroutine and pass it a string(only for this VERY BASIC test)..##Test Module package Test; use strict; use warnings; require Exporter; use vars qw(@ISA @EXPORT); my @ISA = qw(Exporter); my @EXPORT = qw( Prt Time ); sub Prt { my $string = shift; print &Time() . "- $string\n"; } sub Time { my @localdate = localtime(time); my $tme = sprintf("%02d:%02d:%02d", $localdate[2], $localdate[1], +$localdate[0]); return($tme); } 1;
This is what I get...#! /usr/bin/perl use strict; use warnings; use Test; print "About to use Module\n"; &Prt("This is a test in the Mod"); print "Finished\n";
I tried changing line 8. toAbout to use Module Undefined subroutine &main::Prt called at C:\dev\Source_Perl\MiscTests +\mod.pl line 8.
as well as&Test::Prt("This is a test in the Mod");
Test::Prt("This is a test in the Mod");
as was suggested in a previous post but still get the same output.Any help would be greatly appreciated.J9
Back to
Seekers of Perl Wisdom