Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Here's my code:

use Geography::NationalGrid::IE; my $point1 = new Geography::NationalGrid::IE( GridReference => 'M 345132', ); my $point2 = new Geography::NationalGrid::IE( Latitude => 53.8, Longitude => -7.5 ); print "Point 1 is " . $point->latitude . " degrees north\n";
This gives me the error: Can't locate object method "deg2rad" via package "Geography::NationalGrid" at C: /Perl/site/lib/Geography/NationalGrid/IE.pm line 7.

How can I solve this?

Thanks!

Replies are listed 'Best First'.
Re: Package mismatch
by JavaFan (Canon) on Dec 29, 2010 at 18:01 UTC
    You create $point1 and $point2, but you use $point. That could be a cut-and-paste error, but it also may be the culprit.

    And in general, you're better off using the

    Package::Foo->new()
    syntax instead of the indirect object method.
      Thanks! If my perl file contains only:
      use Geography::NationalGrid::IE;
      I still get the error. Any ideas.
        I downloaded the package, read the manual page, and saw the manual page uses:
        use Geography::NationalGrid;
        So, I tried:
        $ perl -MGeography::NationalGrid::IE -we1 Can't locate object method "deg2rad" via package "Geography::NationalG +rid" at /opt/perl/lib/site_perl/5.12.2/Geography/NationalGrid/IE.pm l +ine 7. BEGIN failed--compilation aborted at /opt/perl/lib/site_perl/5.12.2/Ge +ography/NationalGrid/IE.pm line 7. Compilation failed in require. BEGIN failed--compilation aborted. $ $ perl -MGeography::NationalGrid -we1 $
Re: Package mismatch
by Anonyrnous Monk (Hermit) on Dec 29, 2010 at 18:12 UTC
    How can I solve this?

    Also use Geography::NationalGrid, i.e.

    use Geography::NationalGrid; use Geography::NationalGrid::IE; ...

    (This is required for the constant declarations such as

    use constant MIN_LONG => Geography::NationalGrid->deg2rad('-11d 12m 0s +');

    in Geography::NationalGrid::IE. — The module should probably load Geography::NationalGrid itself (as it obviously depends on it), but it doesn't...)