On Thu, 3 Feb 2005 02:09:53 +0100, Babale Fongo <[EMAIL PROTECTED]> wrote:
> It is a bit weird, but I could workaround it by first joining  the value,
> and splitting it thereafter:
> 
> @splitted = split /\s+/, join "", @found;
> 
> Thanks anyway...
> 
> ||-----Original Message-----
> ||From: Babale Fongo [mailto:[EMAIL PROTECTED]
> ||Sent: Wednesday, February 02, 2005 11:59 PM
> ||To: beginners@perl.org
> ||Subject: Net::SSH (How to split value returned by a system command)
> ||
> ||This is what I had:
> ||
> ||@found = remote_cmds ("find $remdir  -name '*.zip'");
> ||
> ||print "@found" look like this:
> ||
> ||/path/file1.zip
> ||/path/file2.zip
> ||/path/file3.zip
> ||
> ||@found is neither a list nor string, so it is not handy to deal with.
> ||
> ||
> || In scalar context, the command returns 1 (true), in list context it
> returns
> ||a list of files (one per line).
> || But the value of @found is not a list, but I can't split it either.

Actually, it's both.  It returns 1 in a scalar context becuase there
is only one item.  In list context it returns a list because it's an
array, but it's a list of 1 item.  Net::SSH is returning a single
scalar with embedded newlines.  Be careful looking to print to halp
you figure yout what type of data your dealing with; it's very
misleading.  it prints on separate lines because of the newlines, but
it's all stored in $found[0] as
"/path/file1.zip\n/path/file2.zip\n/path/file3.zip\n".

'split /\n/, $found[0]' will give you the bahvior you're looking for. 
Since Net::SSH is returning the captured buffer as a scalar, though,
you can just use

$found = remote_cmds ("find $remdir  -name '*.zip'") ;
@splitted = split /\s/, $found; 

HTH,

--jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to