【发布时间】:2012-09-27 16:05:12
【问题描述】:
我正在尝试打开一个路径包含空格的文件,比如:
open(FILE, "some\\path with spaces")
我在 Windows 上使用ccperl,我收到错误“无法打开文件”。
我已经尝试过q!"..."! 尝试过"\path\ with\ spaces" 等等...
有什么想法吗?
【问题讨论】:
我正在尝试打开一个路径包含空格的文件,比如:
open(FILE, "some\\path with spaces")
我在 Windows 上使用ccperl,我收到错误“无法打开文件”。
我已经尝试过q!"..."! 尝试过"\path\ with\ spaces" 等等...
有什么想法吗?
【问题讨论】:
让我们看看。在我的 ActivePerl 5.14.2 上,我可以执行以下操作:
#!C:\perl\bin\perl.exe
use strict; use warnings;
open my $fh, '<', 'C:\Dokumente und Einstellungen\user\Desktop\file spaces.txt'
or die $!;
print while <$fh>;
close $fh;
与您所做的不同之处在于我使用了单引号'。在它们内部,反斜杠\ 不被视为元字符,因此无需转义它。您也不需要转义空格。你应该试试看。
顺便说一句,您是否使用strict 和warnings?他们可能会告诉你哪里出了问题,我的or die $! 可能会。
我还建议您使用open 和lexical filehandles 中的three argument form。
【讨论】:
来自this matrix,ccperl 通常表示带有 ClearCase 的 perl 5.8.6。
ccperl scripts examples 建议:"\"your file path\"",但这可能与 open 不兼容。
【讨论】: