您的位置:首页 > 其它

【转载】perl接受传递参数的方法

2014-12-26 17:30 239 查看
#! /usr/bin/perl

use Getopt::Std;
use warnings;
use strict;

sub read_from_sh($) {
my $file = shift;
my @files = ();
open F, $file or die "Could not open $file: $!";
while (<F>) {
next if /^\s*$/;
push @files, $_;
}
close F or die "Could not close $file: $!";
return @files;
}

my @files;
my %opts = ();
getopts("s:", \%opts);
if ($opts{'s'}) {
@files = read_from_sh($opts{'s'});
}else {
@files = @ARGV;
}
for my $file (@files) {
print "file: $file\n";
}

export.pl同级目录下: chage.csv chage2.csv txt.txt t.txt

>perl export.pl chage.csv chage2.csv txt.txt t.txt

OUTPUT:

file:export.pl

file:chage.csv

chage2.csv

file:txt.txt

file:t.txt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: