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

I trying to use the Net::SFTP and I am getting errors:
"requires explicit package name" Please help.
use strict; use warnings; package Net::SFTP; my %args = (ssh_args => {}); $args(user) = $user $args(password) = $password $args(ssh_args)->(port) = 22; my $sftp = Net::SFTP->($host, %args); my $user = 'test@testserver'; my $password = 'password';

Replies are listed 'Best First'.
Re: SFTP Compile Errors
by Corion (Patriarch) on Feb 29, 2008 at 08:51 UTC

    You don't tell us the full error message. Perl also told you, what requires the explicit package name.

    Your code is riddled with logical and syntactical errors:

    The syntax for accessing or setting a hash entry uses squiggly brackets, not parentheses. Use $args{user} instead of $args(user) which makes no sense.

    Some of your lines do not end with a semicolon even though the statement seems to be complete at the line.

    You set and declare $user and $password later than you use them. This is likely what Perl complains about. You need to move these lines upwards in your program.

    You call Net::SFTP->($host, %args);, but I don't know what it should do. Maybe you can tell us what you expect it to do and where in the Net::SFTP documentation you found that.

Re: SFTP Compile Errors
by stiller (Friar) on Feb 29, 2008 at 08:49 UTC
    You declare package Net::SFTP, but you should use Net::SFTP
Re: SFTP Compile Errors
by moritz (Cardinal) on Feb 29, 2008 at 08:47 UTC
    $args(user) ^ ^

    Those need to be curly braces.