1

I have a test file that looks like this:

my $int = new Services::Plugins::FTP::ftp;
$int->AddUser("durr");

The module has this code:

sub AddUser {

my( @username ) = @_;
print "@_\n";  

}

But my results looks like: Services::Plugins::FTP::ftp=HASH(0x2490160)durr

I just want 'durr'.

Why am I getting the extra stuff?

3 Answers 3

9

You're dealing with object-oriented Perl. If you call a function on an object instance, as in your case with $instance->function(), then the very first parameter is the reference to the instance itself. It is most often called $self.

A commonly used idiom is to write instance methods like this:

sub some_method {
  my ($self, @args) = @_;
}

I suggest you read up on Perl's object-oriented system in the perlootut man page (a good tutorial).

Sign up to request clarification or add additional context in comments.

Comments

5

The first argument to $foo->bar() is $foo

sub AddUser {
    my($self, @username ) = @_;
    print "@_\n";  
}

Comments

3

You are using Object Oriented approach ($int->AddUser("durr") is a method invocation). When calling a method, the first argument is always the object or the class the method should be applied to.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.