我正在做一個關於提取tar.gz文件與指定的位置,但當我運行我的代碼的Perl腳本。使用Perl腳本提取tar.gz文件
use strict;
use warnings;
use Archive::Tar;
use File::Spec::Functions qw(catdir);
my $input = "sample.tar.gz";
my $tar = Archive::Tar->new($input);
my @files = $tar->list_files;
my $output_dir = '/var';
foreach my $file (@files) {
my $extracted_file = catdir($output_dir, $file);
$tar->extract_file($file, $extracted_file);
if ($file =~ /\.rpm\z/ /\.sh\z/ /\.gz\z/) {
open my $fh, '<', $extracted_file or do { warn "$0: Can't open file $file: $!"; next };
while (defined(my $line = <$fh>)) {
do something with $line
}
close $fh;
}
}
我腳本的文件名是「extract.pl」,所以當我運行這個腳本時。我得到這個錯誤
./extract.pl: line 1: use: command not found
./extract.pl: line 2: use: command not found
./extract.pl: line 4: use: command not found
./extract.pl: line 5: syntax error near unexpected token `('
./extract.pl: line 5: `use File::Spec::Functions qw(catdir);'
任何人都可以幫我解決這個問題嗎?
感謝您的編輯.. :) – user3534255