【转载】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
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
相关文章推荐
- 用javascritp脚本在页面中传递参数和接受参数的方法
- c#用匿名方法传递参数给线程(可不用拆箱和装箱,传任意个参数)【转载】
- 用javascritp脚本在页面中传递参数和接受参数的方法
- 【转载】asp,net中参数的传递方法
- perl参数传递的三种方法
- structs2 接受参数的三种方法(转载)
- 阅读下面代码,程序列举了3种二维数组作为参数传递的方法:[转载]
- [转载]AS3)Flash(非Flex)开发中通过事件传递参数的一种方法
- MVC 中前端传递Json数据,后端以对象形式接受参数的处理方法
- 可以把List<String>传递给一个接受List<Object>参数的方法吗?
- require方法接受以下几种参数的传递:
- ref与out的区别(方法参数的传递)【转载】
- asp.net页面参数传递几种方法的比较 (转载)
- jsp URI传递参数,对方接受是乱码解决方法
- 简单的网页间传递参数方法
- JavaScript实现页面之间传递参数的方法
- perl 子程序传递参数不同类型变量 设置
- PB中调用API函数时传递数组参数的方法
- 页面之间传递参数得几种方法
- 给Web Services方法传递数组参数