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"


In reply to Re: How to get a package by telnet by arturo
in thread How to get a package by telnet by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.