Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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 = ""; 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 = ""; 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 = ""; 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 = ""; my $content = record::get($url); # because that's the package declared + above

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


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://253706]
[stevieb]: 16.96 hours of runtime of a Raspberry Pi on a 12v, 7.2Ah battery :) Now to watch now long it takes to recharge the battery completely with my 18v solar cells in the sun :)
[stevieb]: my high-range estimate was 18 hours
[stevieb]: battery was at about 95% capacity when the test began

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2017-03-26 15:21 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (315 votes). Check out past polls.