我正在做一个关于提取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