I have been unable to replicate your problem -- your
code works fine for me (with all the CGI stuff cleaned
out, anyhow). Are you sure the original file isn't empty?
Is that file uploaded to the CGI, which then sends it on?
If so, perhaps there's a bug elsewhere in your program. Note
that I'm assuming it's a cgi because of the calls to
param(). I can see that you're also new to perl, and
probably came from C. Allow me to suggest that string
handling doesn't need to be as complex as you make it out
to be. Compare
my $localfile = sprintf("%s/%s",
$params->get("Path.From"),
$params->get("File"));
to
my $localfile = params->get("Path.From") . '/' . $params->get("File");
You also are using more than one variable with the same
name, which can be confusing. I suggest you examine
your usage of @hosts and $hosts in your program. Without
the cleanup I did to make it not require CGI, I doubt your
program would do what you'd expect it to. Below are some more comments..
- You're not actually using the argument you're
recieving to this function. $hosts and @hosts are not
the same variable. Your initial assignment gives
$hosts the first parameter to this function, which
you then ignore. Instead, maybe you should try something
more like
my ($host, $login, $scrambled_pass) = @_;
and not keep all that stuff in an array? A descriptive
variable name (or hash key) is a lot more descriptive than
a numeric index.
- You're overusing 'my'. You only use it once per
subroutine, and it's best (IMO) to declare variables with it
where you first use them, not up at the top.
- You're probably unintentionally misusing types, and
accidentally taking references to anonymous things. Your
my $host = { 'host' => $hosts->[0],
'login' => $hosts->[1],
'pass' => $pass
};
is taking a reference to an anonymous hash. That's fine, but
why arn't you just using a normal hash in this case? I
think that it's also a symptom of the same thing that you
declare a lot of unused variables at the top of your
procedure.
- You comment too much. If you line up your braces, or
use a better programmer's text editor, you won't need to
comment ends of blocks.
I hope this helps.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.