Hi, I'm trying to implement overriding methods. This is my code:

Base class:

use Net::Telnet(); use strict; use warnings; package L_Switch; sub new { my $class = shift; my ($location, $ip, $time, $client) = @_; my $self = {}; my $sucClass; if ((defined $client) and ($client eq "Veda")){ $subClass = "L_Switch::L_Veda"; } eval "use $subClass;"; eval "\$self = $subClass -> new();"; } sub login { my $self = shift; my $utility = L_Utility -> new(); $self -> {'telnetConn'} -> open($self -> {ip}); $self -> {'telnetConn'} -> login($self -> {'username'}, $self -> { +'password'}); if ($self -> {'time_out'} == 1) # checking +timed-out switches { $self -> {'full_info'} = $self -> {'full_info'} . "," . $self +-> {'location'}; $self -> {'full_info'} = $self -> {'full_info'} . "," . $self +-> {'fault'} . "," . $self -> {'time'} . ",,,,,"; return $self -> {'full_info'}; } return "0"; } 1;

Child class:

package L_Switch::L_Veda; require L_Switch; @ISA = qw(L_Switch); use strict; use warnings; use NET::SSH2; sub new { } # something in here sub login { my $self = shift; $self -> {'ssh'} -> connect($self -> {'ip'}); $self -> {'ssh'} -> auth_password($self -> {'username'}, $self -> +{'password'}); return 0; } 1;

Main script:

use L_Switch; use strict; use warnings; my $utility = L_Utility -> new(); my $switch = L_Switch -> new("", '127.0.0.1', "", "Veda"); $switch -> login(); print $switch -> getFullInfo();
when I run the script, an error appeared: Can't locate object method "login" via package "L_Switch::L_Veda" at testSSH.pl line xx. Can anyone tell me what went wrong in my code. Thanks in advance

In reply to Perl does not recognize object method by lightbringer

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.