首页 > 其他 > 详细

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

时间:2014-12-26 18:36:05      阅读:307      评论:0      收藏:0      [点我收藏+]

#! /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

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

原文:http://www.cnblogs.com/hzj680539/p/4187249.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!