Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Use, Exporter, I'm Dizzy.

by logie17 (Friar)
on Feb 07, 2007 at 17:23 UTC ( #598825=note: print w/replies, xml ) Need Help??


in reply to Re: Use, Exporter, I'm Dizzy.
in thread Use, Exporter, I'm Dizzy.

Thank you for your response, that answers one of my questions. I renamed test.pm to test2.pm and my code now looks like this:
#! /usr/bin/perl use warnings; use strict; use test2(); my $output = testroutine(); print $output, "\n";
Outputs...
$ ./test.pl This is a test
However, how come I'm even able to call testroutine? I didn't think that use would populate my name space? Is it because I don't have package defined at the top of the module? Therefore it's assuming the subroutine is part of Main? Hope that makes sense.
Thanks again,
s;;5776?12321=10609$d=9409:12100$xx;;s;(\d*);push @_,$1;eg;map{print chr(sqrt($_))."\n"} @_;

Replies are listed 'Best First'.
Re^3: Use, Exporter, I'm Dizzy.
by ysth (Canon) on Feb 07, 2007 at 17:28 UTC
    Is it because I don't have package defined at the top of the module? Therefore it's assuming the subroutine is part of Main?
    Yes. All the () on use Foo () does is suppress calling Foo->import - when the module directly defines things in the main package, or exports things in its toplevel code, that's not affected.
Re^3: Use, Exporter, I'm Dizzy.
by ikegami (Patriarch) on Feb 07, 2007 at 17:32 UTC

    I didn't think that use would populate my name space?

    Your module didn't tell perl which namespace to use, so perl placed your symbols in the currently active namespace (main). The fix is to specify a package in your module. See my post for details.

Re^3: Use, Exporter, I'm Dizzy.
by ferreira (Chaplain) on Feb 07, 2007 at 17:36 UTC

    Now that depends on the code in "test2.pm" which you have not shown up. If you're using Exporter, conventionally a statement such as

    use test2 ();

    does not export anything into the callee's namespace. You should be doing something weird and then getting weird behavior back. Take a look at the code written by ikegami at Re: Use, Exporter, I'm Dizzy. to see how the exporting code of your module should look like.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://598825]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2022-08-09 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?