문제

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