【发布时间】:2014-06-09 05:40:22
【问题描述】:
我正在做一个关于提取指定位置的 tar.gz 文件的 Perl 脚本,但是当我运行我的这段代码时。
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);'
谁能帮帮我?
【问题讨论】:
-
感谢您的编辑.. :)