質問

I'm not able to change the dir in perl.

#!/usr/bin/perl
use strict;

my $dir=`date +%d%b%Y`;
#the output of $dir is 13Feb2014 that directory is already inside "/mnt/Recordings/Inbound/Kinrep/" 

my $path = "/mnt/Recordings/Inbound/Kinrep/$dir";        
chdir($path) or die "Cant chdir to $path $!";

whenever i'm executing my program i'm not able to change the directory i got following error.

Cant chdir to /mnt/Recordings/Inbound/Kinrep/13Feb2014
 No such file or directory at Ftp_transfer_197.pl line 17.
役に立ちましたか?

解決

chomp $dir; will remove the newline that the command in the backticks appended to its output. It's very rare that a directory name actually contains a newline, although it's possible on many file systems.

他のヒント

You have a solution, which you have accepted. But I wanted to point out that this is a side-effect of you using an external program to do something that you can do perfectly well within Perl. There are many ways to do what you want. The simplest is probably to use the (standard) Time::Piece module.

use Time::Piece;

$dir = localtime->strftime('%d%b%Y');
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top