Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
When I run the program, it told me:package record;
I use LWP. What can I do about that? Please help!!! Thanks in advance!!!Undefined subroutine &record::get called at ....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get a package by telnet
by jonadab (Parson) on Apr 28, 2003 at 14:12 UTC | |
There are two ways to answer your question. I'm going to start with the obvious way (which takes you at your word and assumes you know what package means). Undefined subroutine &record::get called at This means you didn't define that subroutine, or maybe you defined it before your package declaration. If you defined sub get first before your package declaration, then it will be main::get rather than record::get. After the package declaration you're in the record package, so get() is the same as record::get(), which is _not_ the same as main::get(). If you need to use get() inside of your package, you should probably declare and define it inside of your package (i.e., after the package declaration). It might be best to put the package declaration at the very beginning of your module, at the top of the file.
The other possibility is that you have misunderstood what package does. If you think "package foo" gives you access to some other foo package that someone else has written so that you can use it, then you have package confused with either use (probably) or require (possibly, if the package is not installed in the usual way). If what you're trying to do is use someone else's package, then you should use it, roughly as follows:
I'm not familiar with the record package, so the above may not be exactly right. See the documentation for the package in question. I'm not at all sure that I've answered your question, because I don't understand what telnet has to do with anything, so if these answers don't seem right, maybe you need to clarify the question.
| [reply] [d/l] [select] |
|
Re: How to get a package by telnet
by cfreak (Chaplain) on Apr 28, 2003 at 13:53 UTC | |
We can't help you unless you post code and what you are trying to do. Are you using Telnet in your program? What are you using LWP for? Are you trying to write a package called 'record' or are you trying to use it? So many questions. Making some assumptions: If you're writing a package called record then you need to define a get() subroutine within that package. If you are going to use telnet inside your program then look into Net::Telnet. Hope that helps ChrisLobster Aliens Are attacking the world! | [reply] |
by Anonymous Monk on Apr 28, 2003 at 14:15 UTC | |
Please help!!! Thanks!!! | [reply] [d/l] |
|
Re: How to get a package by telnet
by arturo (Vicar) on Apr 28, 2003 at 14:29 UTC | |
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? | [reply] [d/l] [select] |
|
Re: How to get a package by telnet
by hardburn (Abbot) on Apr 28, 2003 at 14:00 UTC | |
I assume that by "working by telnet", you mean you're logging into a system via telnet and writing code from there. If that is the case, there is nothing special you have to do to the code. Logging in from telnet and writing code is no different from logging onto a local system and writing code. I suspect your problem is elsewhere. For one thing, packages with all lowercase names are reserved for pragmas. A quick scan through the Camel didn't show me any existing pragmas named "record" (but perhaps this has changed since it was written?), so the code you have should still work. Even so, you should consider changing it to "My::Record" or something similar. The "My::" namespace is for packages that are never intended to be distributed outside your orginization. ---- Note: All code is untested, unless otherwise stated | [reply] |
|
Re: How to get a package by telnet
by Aristotle (Chancellor) on Apr 28, 2003 at 13:52 UTC | |
Makeshifts last the longest. | [reply] |