http://qs321.pair.com?node_id=598820

logie17 has asked for the wisdom of the Perl Monks concerning the following question:

Could somebody please explain why the following does this?
#! /usr/bin/perl use warnings; use strict; use test(); my $output = testroutine(); print $output, "\n";

and this has the same result...
#! /usr/bin/perl use warnings; use strict; use test; my $output = testroutine(); print $output, "\n";
the result being...
Undefined subroutine &main::testroutine called at ./test.pl line 8.
If I run the following:
$ perl -e 'map {print $_,"\n"} @INC' /usr/lib/perl5/5.8/cygwin /usr/lib/perl5/5.8 /usr/lib/perl5/site_perl/5.8/cygwin /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/site_perl/5.8/cygwin /usr/lib/perl5/site_perl/5.8 /usr/lib/perl5/vendor_perl/5.8/cygwin /usr/lib/perl5/vendor_perl/5.8 /usr/lib/perl5/vendor_perl/5.8/cygwin /usr/lib/perl5/vendor_perl/5.8 .
Now if I alter test.pl to look like:
#! /usr/bin/perl use warnings; use strict; use lib '.'; #My Change use test(); my $output = testroutine(); print $output, "\n";
When run, the program outputs the following:
This is a test
For information test.pm which is in the same directory as test.pm has the following code:
sub testroutine { return "This is a test"; } 1;
Now I may be very ignorant of the use. However, I would expect my first example to work if my second example works. Why would enabling use lib import the module into my namespace? When before I use use lib, '.' is in my @INC. Second, I would think that in actuality both examples should fail since I'm calling test.pm by use test(), I would think this would NOT populate anything into my namespace? I hope this long post makes sense, for I am eager to learn.

Thanks!
s;;5776?12321=10609$d=9409:12100$xx;;s;(\d*);push @_,$1;eg;map{print chr(sqrt($_))."\n"} @_;