1/ When you use or require a module Perl loads it and compiles it. Perl then executes any "main line" code in the module and checks that the result is true. For most modules the "main line" code may be as simple as 1; which is equivalent to return 1; and returns the true result Perl expects. More interesting work done by a module during loading includes initialising variables and perhaps performing any other one time house keeping that the module may need (even including connecting to a database for example).

From 1/ above you may figure out that the load process will see return $tag, $bag 1; as the result from loading the module. If you had used strictures in the module (use strict; use warnings;), which you should always do, you would have received a number of "Use of uninitialized value" messages too. Because there are no parameters passed in $tag and $bag are undefined which is false so the module load fails. Module Test (note the upper case first letter - it's important) should look like:

use strict; use warnings; package Test; sub SubInTest { my $tag = $_[0]; $tag =~ s/p/n/; my $bag = $_[1]; $bag =~ s/k/p/; return $tag, $bag; } 1;

Note that strictly lower case module names are reserved by Perl for use as pragmata such as strict and warnings. You can use such names, but shouldn't in case Perl decides it wants to in some future version.

2/ By now it should be clear that, except for unusual modules (which only export data for example), it is futile to have a subroutine-less module because you can't execute any code in it after it's been loaded.

True laziness is hard work

In reply to Re^3: How to give input and collect output of a perl script using another perl script by GrandFather
in thread How to give input and collect output of a perl script using another perl script by chakreey

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.