in reply to SSH connection with module

You are not persisting an object and associated states.

You end up creating two completely separate Expect objects.

You should create a cisco::new() method that creates an object (see 'perldoc perltoot') - this method should look something like this:

sub new{ my ($class, $logname) = @_; $logname or die "NO log file name specified"; my $self = bless {}, $class; # Creating an empty instance $self->{EXP} = Expect::->new(); # Now has an EXP attribute open $self->{LOGFH}, ">>", $logname or die "Could not append to $l +ogname : $!"; return $self; }
Once you get an object back from new(), you need to call login_auth like this:
my $cisco = cisco::->new(); $cisco->login_auth();
Of course, you will need to modify login_auth() to accept a parameter, preferably named $self.

Update: Added LOG to new() method.

So happy journey into the world of OO programming!

If you run into concept issues with how or why things are done is a certain way, be sure to post specific questions here, for assistance.

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992

Replies are listed 'Best First'.
Re^2: SSH connection with module
by MysticRyuujin (Novice) on Mar 10, 2014 at 01:40 UTC
    I got most of that but I have no idea what you mean by "you will need to modify login_auth() to accept a parameter, preferably named $self." Don't I have to use this because I have to pass the variables:
    $cisco->login_auth(@ARGV);
    I get that sub new is returning an object into the main script but I don't get how I then pass it back to the module and use it then pass it back? Am I even understanding that right?
      Yes - you are asking the right questions - so you are close to "getting it".

      When you invoke

      $cisco->login_auth( $whatever );
      you are actually passing TWO parameters into login_auth - which you can retrieve using:
      sub login_auth{ my ($self, $whatever) = @_; # Now $self contains whatever sub new() put into it. # and $self can be updated to include more useful things. }
      Instead of passing @ARGV, you should pass it as a reference : \@ARGV.

      This will allow passing additional parameters if necessary.

      OK - next question ?...

              What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                    -Larry Wall, 1992

        No more questions...for now :) That explained it and I've been playing with passing $exp back and forth. I think I'm figuring it out. Thanks!