鉴于可以在unix或Windows上运行的Perl脚本,我如何才能最好地读取/写入Windows主机上的文件?有没有类似File::Remote的内容?
答案 0 :(得分:2)
我会尝试挂载远程文件夹,然后使用标准的perl函数:
use constant W_REMOTE_FOLDER = '\\server\share';
use constant W_LOCAL_FOLDER = 'x:\share\';
use constant L_REMOTE_FOLDER = 'smb://server/share';
use constant L_LOCAL_FOLDER = '/mnt/share/';
my $localfolder = '';
if ($am_i_windows)
{
system('net use ...');
$localfolder = W_LOCAL_FOLDER;
}
if ($am_i_linux)
{
system('mount ...');
$localfolder = L_LOCAL_FOLDER;
}
die "What am I? if ($localfolder eq '');
open(HANDLE, "$localfolder/$filename");
# read/write (...)
close(HANDLE);