나는 여러개의 출력 파일을 생성 한 파일을 파싱 중이다. perl 스크립트가 실행 된 동일한 폴더의 특수 디렉토리에 출력 파일을 저장하고 싶습니다. 디렉토리가 이미 있으면 해당 디렉토리에 파일을 넣으십시오. sudo 권한이없는 사용자는 현재 작업 디렉토리에 파일을 만듭니다.출력 파일을 디렉토리에 저장하고 출력 파일의 이름을 인쇄하는 방법은 무엇입니까?
All done! Please look in 'output.txt' for the output.
출력 파일이있는 경우 : 내가 구문 분석하고 파일을 처리 한 후 스크립트의 끝에서
use strict; use warnings;
sub main {
my $directory = "pwd/test.pl_output";
unless(mkdir $directory) {
return 0; # unable to create directory (it either already exists
# or you don't have sudo privileges)
} else {
return $directory
}
}
if (my $PATH = main()){
open(my $fh, '<', 'input.txt') or die $!;
open(my $output, '+>', $PATH.'/output.txt') or die $!;
} else { # create the output file as usual
open(my $fh, '<', 'input.txt') or die $!;
open(my $output, '+>', 'output.txt') or die $!;
}
print "All done! Please look in \$output\n";
, 나는 쉘 프롬프트에 다음을 인쇄하고 싶습니다 새 디렉토리를 만들려면 다음을 인쇄하십시오.
All done! Please look in 'output.txt' in the directory '~/path/to/output.txt' for the output.
내 코드가 작동하지 않습니다.
필자는 perl에 익숙하지 않지만, 여기에'$ PATH/output.txt''라는 질문이 있습니다. $ PATH에'''안에 값이 대체됩니까? – abasu
abasu 다른 좋은 캐치입니다. 작은 따옴표는 보간하지 않습니다. 나는 우리가 실제 복사 - 붙여 넣기 코드를 보지 못하고 있다고 생각한다. – DavidO
필자는 [perl에서 디렉토리를 생성하는 것이 가능하다는 것을 알고있다] (http://www.caveofprogramming.com/perl/perl-mkdir-how-to-create-directories-in-perl/). 그러나 내가하려는 일의 나머지가 가능한지 나는 모른다. – cooldood3490