Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to get a package by telnet

by arturo (Vicar)
on Apr 28, 2003 at 14:29 UTC ( #253706=note: print w/ replies, xml ) Need Help??


in reply to How to get a package by telnet

When you put package record; in your script, you are telling perl that, until you say otherwise, everything that follows belongs to that package. So, when you have get($url); in your code, what perl looks for is a subroutine named get in the record package, but it's not finding it. That's what your error message means, anyhow, and what I have to say below is pure speculation, because as others have pointed out, you don't give us enough information.

I'm guessing your code looks like this:

use LWP; # or is that LWP::Simple ??? package record; my $url = "http://www.perlmonks.org"; my $content = get( $url );
(If you don't have the use LWP line at all, then you need to add it, but read on anyway). The problem here is that when you call use LWP;, the get function is imported into the default namespace (aka "main"), but not into the record namespace. So, you could fix the problem by reversing the package and use calls:
package record; use LWP; my $url = "http://www.perlmonks.org"; my $content = get( $url );
Which imports the get call from LWP into the record namespace. However, if, as I suspect, you really want to be using the get subroutine from LWP::Simple, you should do this instead:
package record; use LWP::Simple; my $url = "http://www.perlmonks.org"; my $content = get( $url );
As others have noted though, typically lowercase packages are used for pragmas and not modules, so you might want to re-think the name record and use Record instead.

The very gory details. The subroutines' full name is LWP::Simple::get. You can access it through that name anywhere, no matter which package you're in. The use LWP::Simple; directive, along with some behind the scenes stuff, allows you to access that subroutine with a simple get, which perl understands as $CURRENT_PACKAGE::get -- this is called "importing" a symbol (name of something, in this case a subroutine) from one namespace to another. So, when you call use, before package, you import things into the mainpackage, and immediately change the current package. So here's what perl sees, assuming that the first example above is how your code looks:

# we're in package main by default; any unqualified subroutine referen +ce # is understood to refer to a subroutine in the "main" namespace use LWP::Simple; #main::get is now an alias to LWP::Simple::get package record; my $url = "http://www.perlmonks.org"; my $content = record::get($url); # because that's the package declared + above

So that's why get($url) doesn't work.

HTH!

If not P, what? Q maybe?
"Sidney Morgenbesser"


Comment on Re: How to get a package by telnet
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-10-31 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls