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:

h2xs -X -n MyCal::DoStuff

with the requisite skeleton in hand I edited DoStuff.pm to:

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 expo +rt # 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 @EXP +ORT_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 p +rogram. 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

then wrote my first program using it:

#!/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;

This throws errors when run:

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/perl +5/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.p +m 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

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.


In reply to dumb question about perl module creation and use by desertrat

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.