perlquestion
desertrat
<p>So, I'm trying to write some modules for use across a website, and I'm testing a rudimentary first attempt. Following what I discovered on the web I first did:</p>
<code>h2xs -X -n MyCal::DoStuff</code>
<p> with the requisite skeleton in hand I edited DoStuff.pm to:</p>
<code>package MyCal::DoStuff;
use 5.012003;
use strict;
use warnings;
require Exporter;
use AutoLoader qw(AUTOLOAD);
our @ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
# This allows declaration use MyCal::DoStuff ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw($a do_something anumber
);
our $VERSION = '0.01';
our $a =45;
use constant anumber => 85;
sub do_something {
my $input = shift;
my $randno = int (rand 20)+1;
my $out = $input/5 *$randno;
return ($randno, $out);
}
# Preloaded methods go here.
# Autoload methods go after =cut, and are processed by the autosplit program.
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
=head1 NAME
MyCal::DoStuff - Perl extension for blah blah blah
=head1 SYNOPSIS
use MyCal::DoStuff;
blah blah blah
=head1 DESCRIPTION
Stub documentation for MyCal::DoStuff, created by h2xs. It looks like the
author of the extension was negligent enough to leave the stub
unedited.
Blah blah blah.
=head2 EXPORT
None by default.
=head1 SEE ALSO
Mention other useful documentation such as the documentation of
related modules or operating system documentation (such as man pages
in UNIX), or any relevant external documentation such as RFCs or
standards.
If you have a mailing list set up for your module, mention it here.
If you have a web site set up for your module, mention it here.
=head1 AUTHOR
Bruce Johnson, E<lt>johnson@pharmacy.arizona.eduE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2012 by Bruce Johnson
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.12.3 or,
at your option, any later version of Perl 5 you may have available.
=cut
</code>
<p>then wrote my first program using it:</p>
<code>#!/usr/bin/perl
use strict;
use warnings;
use lib '/Users/johnson/MyCal-DoStuff/lib';
use MyCal::DoStuff;
my ($rno, $res) = &do_something(26);
print "a = $a \n";
print "results of sub are random number $rno and result $res \n";
exit;
</code>
<p> This throws errors when run:</p>
<code>dbdev2:~ johnson$ perl test
Can't locate auto/MyCal/DoStuff/autosplit.ix in @INC (@INC contains: /Users/johnson/MyCal-DoStuff/lib /opt/local/lib/perl5/site_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/site_perl/5.12.3 /opt/local/lib/perl5/vendor_perl/5.12.3/darwin-multi-2level /opt/local/lib/perl5/vendor_perl/5.12.3 /opt/local/lib/perl5/5.12.3/darwin-multi-2level /opt/local/lib/perl5/5.12.3 /opt/local/lib/perl5/site_perl /opt/local/lib/perl5/vendor_perl .) at /opt/local/lib/perl5/5.12.3/AutoLoader.pm line 173.
at /Users/johnson/MyCal-DoStuff/lib/MyCal/DoStuff.pm line 8
a = 45
results of sub are random number 14 and result 72.8
</code>
<p>In short, "huh??!??" This was all done 'by the book' No other modules in use in this system throw that error, but they're all on the standard @INC, only MyCall::DoStuff is not.</p>