I commented out use Login and only have use autouse Login => qw(&login &login2); and got the error: Undefined subroutine &main::login called at C:/apache/www/index.pl line 87.

It was okay with use Login uncommented. The code I've is as follows

######### index.pl #!C:/perl5.8/bin/perl.exe use strict; use warnings; use diagnostics; use CGI::Carp qw(fatalsToBrowser); use lib 'C:/apache/www/modules'; #use Login; use autouse Edit => qw(&login &login2); my %actions = ( default => \&default, login => \&login, login2 => \&login2 ); # Thanks to fruiture for pointing this out... $query = 'default' unless exists $actions{ $query }; &{ $actions{$query} } sub default { # show default page } ######### Login.pm use strict; use warnings; use diagnostics; use CGI::Carp qw(fatalsToBrowser); sub login { # display login page } sub login2 { # process login } 1;
Also, I'm wondering why in the Login.pm it doesn't seem I need the usual exporting stuff as follows:
# The package declaration and the code to # do the exporting are absent in Login.pm # Do I need to put them in? package Login; require Exporter; our @ISA = qw(Exporter); our @EXPORT = qw(&login &login2);
update

Got it to work. I do need the package declaration package Login at the top of Login.pm but I don't need to do any exporting as Login.pm is not used by other scripts for its functions. Also, instead of

use autouse Edit => qw(&login &login2);
I should have
use autouse Edit => qw(login login2);
i.e. without the ampersand.

Let me know if I've made any blunders :)


In reply to Re: •Re: Re: •Re: How to use require... by kiat
in thread How to use require... by kiat

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.