Re: Getting error in Net::SFTP with get function



On 10/31/07, Jay Savage <daggerquill@xxxxxxxxx> wrote:

it looks to me like OP is calling $sftp->get() in a void
context:

$sftp->get( $file, $localFile ) || warn("errrrr0rrrrr_--->
$!".$sftp->status."\n");

It may seem that way, but the left side of the logical or operator
isn't a void context, even if the operator itself is used in a void
context. That's actually a Boolean context (which is to say a scalar
context), no matter how the operator is used. That's because the left
side must be evaluated as true or false to determine whether the right
side will be evaluated, even if the whole thing is used in a void
context. Here comes the code:

#!/usr/bin/perl

use warnings;
use strict;

sub my_context {
my $wa = wantarray ? "list" : "scalar";
$wa = "void" unless defined wantarray;
my $line = (caller)[2];
print "Called in $wa context at line $line.\n";
$wa;
}

print "Testing scalar and list context:\n";
my $scalar = &my_context();
my($list) = &my_context();
print "Scalar: $scalar\nList: $list\n\n";

print "Testing left side of ||-or in scalar context:\n";
my $left_of_or = &my_context() || "0 but true";
print "Left of ||-or: $left_of_or\n\n";

print "Testing left side of ||-or in list context:\n";
my($list_left_of_or) = &my_context() || "0 but true";
print "List left of ||-or: $left_of_or\n\n";

print "Testing left side of ||-or in void context:\n";
&my_context() || die "no context";
print "\n";

print "Testing true void context:\n";
&my_context();
print "\n";

At least I'm not aware that that '||' forces any particular context on
the lefthand operand. Perlop mentions propagating context WRT the
righthand operand, but doesn't say anything about the left.

The docs could always be more clear. The right operand of an
or-operator does inherit the context of the operator itself. But the
left operand's context is always Boolean.

Given that, I would expect, from the docs, for get() to return the
empty string on success

Where did you get that? From what I read of the docs, get() should
return the downloaded file contents on success. "If get is called in a
non-void context, returns the contents..."

http://search.cpan.org/~dbrobins/Net-SFTP-0.10/lib/Net/SFTP.pm

Of course, the contents of a file could be the empty string or another
false value, so it would be appropriate to use defined() to test for
success.

Cheers!

--Tom Phoenix
Stonehenge Perl Training
.



Relevant Pages

  • [PATH -mm -v2] Fix a race condtion of oops_in_progress
    ... extern int cause_of_death; ... void machine_restart ... context or a bust_spinlocks cleared the way for us. ...
    (Linux-Kernel)
  • Re: [PATCH 6/6] AIO wait page and AIO lock page
    ... return status (which may be non-zero when the wait queue ... queue parameter is the running task's default io wait context. ... * Get a lock on the page, assuming we need to sleep to get it. ... -extern void FASTCALL); ...
    (Linux-Kernel)
  • Re: Writing a simple function in C#
    ... void CopyFile ... Or we can encapsulate the CopyFile operation to a FileOperation class: ... public FileOperationContext(string source, string destination) ... public FileOperation(FileOperationContext context) ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is it windows bug ? Callback routine get wrong argument ?!
    ... about the type mismatch. ... IN PDEVICE_OBJECT DeviceObject, ... IN PVOID Context ... > VOID USBCAMD_ProcessStillReadWorkITem{ ...
    (microsoft.public.development.device.drivers)
  • RE: VSTO 2005 Beta 2 Outlook Addin: How to create a context menu?
    ... I would not recommend developing a solution around a context menu if you need ... The sample code checks to see if the mail item's subject contains ... to other objects such as a contact or calendar item. ... >> private void ThisApplication_Startup(object sender, ...
    (microsoft.public.vsnet.vstools.office)