【发布时间】:2015-10-12 16:35:39
【问题描述】:
我有以下 perl 脚本,它接收参数文件并将其存储到哈希中。我想修改并将此哈希传递给我正在使用系统命令调用的另一个 perl 脚本:
script1.pl
#!/usr/bin/perl -w
# usage perl script1.pl script1.params
# script1.params file looks like this:
# PROJECTNAME=>project_dir
# FASTALIST=>samples_fastq.csv
use Data::Dumper;
my $paramfile = $ARGV[0];
# open parameter file
open PARAM, $paramfile or die print $!;
# save it in a hash
my %param;
while(<PARAM>)
{
chomp;
@r = split('=>');
$param{$r[0]}=$r[1];
}
# define directories
# add to parameters' hash
$param{'INDIR'} = $param{'PROJECTNAME'}.'/input';
$param{'OUTDIR'} = $param{'PROJECTNAME'}.'/output';
.... do something ...
# @samples is a list of sample names
foreach (@samples)
{
# for each sample, pass the hash values & sample name to a separate script
system('perl script2.pl <hash> $_');
}
script2.pl
#!/usr/bin/perl -w
use Data::Dumper;
## usage <script2.pl> <hash> <samplename>
# something like getting and printing the hash
my @string = $ARGV[0];
print @string;
如果您能帮助我展示如何传递和获取哈希对象(在第二个脚本中打印哈希对象这样简单的事情就可以了),那么我将不胜感激。
谢谢!
【问题讨论】: