
Let's say you make an SSH connection to another host in Perl and obtain some data, such as a list of files.
($stdout) = $ssh->cmd("ls");
In this example, the list of files from the remote host is stored in the $stdout variable. The variable can be printed.
print $stdout;
Printing this variable will print the list of files on the remote host.
file1.txt
file2.txt
file3.txt
The dumper function validates that the entire list of files in a single variable value.
use Data::Dumper;
print Dumper $stdout;
In other words, each files is not associated with a unique variable value.
$VAR1 = 'file1.txt
file2.txt
file3.txt';
Split can be used to create an array, where each file is a unique value in the array.
@files = split(/\n/, $stdout);
And now you should be able to print each item in the array.
print @files;
Which will print each file.
file1.txt file2.txt file3.txt
Dumper can be used to verifiy each item in the array is unique.
print Dumper @files;
The dumper output.
$VAR1 = 'file1.txt';
$VAR2 = 'file2.txt';
$VAR3 = 'file3.txt';
Did you find this article helpful?
If so, consider buying me a coffee over at