似乎perl不接受UNC路径文件名。有没有人知道一种解决方法?
我尝试了UNC和URL表单。转义反斜杠会产生与仅使用单个反斜杠相同的结果。
13:35:39.28 C:\test\t
C:> perl -v | head -2 -
This is perl, v5.10.0 built for MSWin32-x86-multi-thread
13:35:40.43 C:\test\t
C:> type ft.pl
#!/usr/bin/local/perl
use Time::localtime;
$mtime=(stat("ft.pl"))[9];
$t=localtime($mtime);
print sprintf("%04d-%02d-%02d %02d:%02d:%02d\n", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec);
$mtime=(stat("\\\\zzz047922\\c$\\test\\t\\ft.pl"))[9];
$t=localtime($mtime);
print sprintf("%04d-%02d-%02d %02d:%02d:%02d\n", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec);
$mtime=(stat("//zzz047922//c$/test/t/ft.pl"))[9];
$t=localtime($mtime);
print sprintf("%04d-%02d-%02d %02d:%02d:%02d\n", $t->year + 1900, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec);
13:35:50.62 C:\test\t
C:> perl ft.pl
2014-03-18 13:29:35
1969-12-31 17:00:00
1969-12-31 17:00:00
非常感谢,池上。我应该这样做,但我正在修理一个单行并没有想到它。这是生成的脚本。
M:> type getfiletimestamp.bat
@echo off
SETLOCAL
SET EXITCODE=0
IF "%1" == "" (ECHO usage: %0 ^<filename^> & SET EXITCODE=1 & GOTO TheEnd)
IF NOT EXIST "%1" (ECHO file "%1" does not exist & SET EXITCODE=2 & GOTO TheEnd)
SET FT=%~f1
SET F=%FT:\=/%
SET F=%F:$=\$%
perl -e "{use Time::localtime; $mtime=(stat(\"%F%\"))[9]; $t=localtime($mtime); print sprintf("%%04d-%%02d-%%02d %%02d:%%02d:%%02d\", $t->year + 1900
, $t->mon + 1, $t->mday, $t->hour, $t->min, $t->sec );}"
:TheEnd
EXIT /B %EXITCODE%
答案 0 :(得分:2)
始终使用use strict; use warnings;
!
>type x.pl
use strict;
use warnings;
print "\\\\zzz047922\\c$\\test\\t\\ft.pl", "\n";
>perl x.pl
Use of uninitialized value $\ in concatenation (.) or string at x.pl line 3.
\\zzz047922\c est\t\ft.pl
现在去逃避$
或切换到单引号。