I have a strange question involving modules, subroutine prototypes, and hard references. I am running this under NT. Perl version is ActivePerl build 620 (5.6.0). When I define a subroutine in my script as such:
sub DoSomething( $\$\$ )
and then call it as
my $name; my $path; my $count; DoSomething( $name, \$path, \$count );
everything works fine. So good so far. But, if I move the DoSomething subroutine into a module such as
package MyModule; require Exporter; @ISA = qw( Exporter ); @EXPORT = qw( DoSomething ); sub DoSomething( $\$\$ )
then I get the following error:
Type of arg 2 to MyModule::DoSomething must be scalar (not single ref +constructor) at D:\dlkusters\vsstools\ss2Sink.pl line 56, near "$path + )" Type of arg 3 to MyModule::DoSomething must be scalar (not single ref +constructor) at D:\dlkusters\vsstools\ss2Sink.pl line 56, near "$coun +t )" Execution of D:\dlkusters\vsstools\ss2Sink.pl aborted due to compilati +on errors.
Why does the prototype work in the same script but fail the moment I put it in a module? BTW, if I change the prototype in the module subroutine to
sub DoSomething( $$$ )
then everything works again. This is not my preferred solution since I'm avoiding using prototypes correctly. Thanks, Dave

In reply to Modules, Prototypes, and References by Anonymous Monk

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.