Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-03-19 08:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found