我在Main.pl脚本中创建了一个变量$ date,我希望将其传递给Annotator.pl脚本。我使用shell脚本来执行Annotator.pl。我无法弄清楚如何将$ date传递给Annotator.pl。当我在Annotator.pl中运行my $date = $ARGV[0];
时,我得到了当前目录的名称,但是$date = $ARGV[1];
没有返回任何内容。
请参阅下面的代码。日期很重要,因为它必须准确,我无法弄清楚如何将它传递给Annotator.pl。谢谢你的帮助。
Main.pl脚本:
#!/usr/bin/perl -w
use strict;
use warnings;
my $sec; my $min; my $hour; my $mday; my $mon; my $year; my $wday; my $yday; my $isdst;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon=$mon+1; $year = 1900+$year;
if (length($mon)==1) {$mon="0".$mon;}
if (length($mday)==1) {$mday="0".$mday;}
if (length($hour)==1) {$hour="0".$hour;}
if (length($min)==1) {$min="0".$min;}
if (length($sec)==1) {$sec="0".$sec;}
my $date = "$mon"."_"."$mday"."_"."$year"."-".$hour.$min.$sec;
my $cmd5 = `perl MDL_unzip_annotate.sh /data/test_all_runs pVCF $date`; print "$cmd5";
Shell脚本:执行Annotator.pl
的MDL_unzip_annotate.shhome="/data/test_all_runs" #location of the run directory from which the program is launched
scripts="/data/test_scripts"
datapath=$1 #this is called in Main.pl as [test_all_runs]
process=$2 #the process
if [[ "$process" == "pVCF" ]];then
cd $datapath
folders="$(ls)"
cd $scripts
for ff in $folders; do
dname=$ff
echo $dname
if [ ! -f $dname ];then
cmd2="perl Annotator.pl $dname"
echo $cmd2
cmd2=`perl Annotator.pl $dname`
echo $cmd2
fi
done
done
fi
Annotator.pl脚本:
#!perl
use strict;
use warnings;
my $date = $ARGV[1]; print "the date is######## ".$date."\n";
答案 0 :(得分:1)
我将使用以下代码捕获特定目录中文件夹的名称,而不是使用shell脚本:
opendir my $dir, "/data/test_all_runs" or die "Cannot open directory: $!";
my @run_folder = readdir $dir;
closedir $dir;
my $last_one = pop @run_folder; print "The folder is".$last_one."\n";
感谢您的建议。