File :: Util make_dir不需要的输出

时间:2010-12-04 14:57:02

标签: perl perl-module

当使用这个sub时,如果我传递一个包含错误字符的目录,它会将其输出发送到控制台,如下所示:

PROCESS TERMINATED DUE TO ERRORS

File::Util can't use this string for �the name of a directory�.
   �ddd??---?d�
It contains illegal characters.

Illegal characters are:
   \   (backslash)
   /   (forward slash)
   :   (colon)
   |   (pipe)
   *   (asterisk)
   ?   (question mark)
   "   (double quote)
   <   (less than)
   >   (greater than)
   \t  (tab)
   \ck (vertical tabulator)
   \r  (newline CR)
   \n  (newline LF)

Origin:     This is a human error.
Solution:   A human must remove the illegal characters from this string.

ARG   _pak = File::Util
ARG   purpose = the name of a directory
ARG   string = ddd??---?d

1. File::Util::_throw
    -called at line (1343) of blib/lib/File/Util.pm (autosplit into blib/lib/auto/File/Util/make_dir.al)
       -was called with args
       -was not called to evaluate anything


2. File::Util::make_dir
    -called at line (35) of importdatafiles.pl
       -was called with args
       -was not called to evaluate anything


3. (eval)
    -called at line (35) of importdatafiles.pl
       -was called without args
       -was not called to evaluate anything

如何抑制此输出(我只想在没有所有这些详细信息的情况下打印“Bad”)

2 个答案:

答案 0 :(得分:2)

使用File::Path qw / mkpath /?我不知道它是否在Windows下运行,但值得一试。

答案 1 :(得分:0)

“只是抑制输出”可能可以通过eval / die构造来完成。像这样:

eval { make_dir (...) };
if ($@) { die "nice short error message" };

然而,这个长错误信息仍然令我震惊。如此侮辱我将其误认为是Windows CLI实用程序输出,您可以看到:)