![]() |
|
Keep It Simple, Stupid | |
PerlMonks |
Re: How to get a package by telnetby arturo (Vicar) |
on Apr 28, 2003 at 14:29 UTC ( #253706=note: print w/replies, xml ) | Need Help?? |
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: (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: 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: 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:
So that's why get($url) doesn't work. HTH! If not P, what? Q maybe?
In Section
Seekers of Perl Wisdom
|
|