开发者

Error when using complex file names for tar -> write in perl

开发者 https://www.devze.com 2023-01-24 04:18 出处:网络
While using tar->write() I am getting errors while using complex file names. The code is: my $filename= $archive_type.\"_\".$from_date_time.\"_\".$to_date_time.\"tar\";

While using tar->write() I am getting errors while using complex file names.

The code is:

my $filename= $archive_type."_".$from_date_time."_".$to_date_time."tar";
$tar->write($filename);

The error i get is: Could not create filehandle for 'postProcessProbe_2010/6/23/3_2010/6/23/7.tar':

No such file or directory at test.pl line 24

If I change the $filename to a simple string like out.tar e开发者_开发技巧verything works.


Well, / is the directory separator on *nix systems (and, internally Windows treats / and \ interchangeably) and I believe tar files, regardless of platform use it internally as the directory separator.

I do not think you can create file names containing / on either *nix or Windows based systems. Even if you could, that would probably create a whole bunch of headaches down the road.

It would be better in my humble opinion to switch to a saner date format such as YYYYMMDD.

Also, you are using string concatenation when sprintf would have been much clearer:

my $filename= sprintf '%s_%s_%s.tar', $archive_type, $from_date_time, , $to_date_time;

0

精彩评论

暂无评论...
验证码 换一张
取 消