gpt4 book ai didi

perl - Getopt::Long::Descriptive - 如何声明变量

转载 作者:行者123 更新时间:2023-12-04 04:40:08 24 4
gpt4 key购买 nike

我试图通过命令行指定变量,但我不确定如何声明变量。这些是错误:

$ perl make_keggTable.pl -i ko2genes.pau -o pau
Global symbol "$inlocus" requires explicit package name at make_keggTable.pl line 126.
Global symbol "$inlocus" requires explicit package name at make_keggTable.pl line 126.
Global symbol "$orgCode" requires explicit package name at make_keggTable.pl line 133.
Global symbol "$orgCode" requires explicit package name at make_keggTable.pl line 146.

我的代码:
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long::Descriptive;
#use Getopt::Long;
#use Pod::Usage;

## usage and help info
my ( $opt, $usage ) = describe_options(
'make_keggTable.pl %o',
[ 'inlocus|i=s', 'file of NCBI locus IDS to Kegg KOs' ],
[ 'orgCode|o=s', 'kegg organism code(Pseu.PA14=pau, Pseu.PA01=pae,Salm.14028S=seo,Salm.LT2=stm,Ecoli.MG1655=eco)'],
[],
[ 'verbose|v', 'print with verbosity' ],
[ 'help', 'print usage message and exit' ],
);

if ($opt->help) {
print $usage->text, "\n";
}
##
### read in NCBIgenID to KO for organism
# pau:PA14_00010 K02313
#my $inlocus=$ARGV[0] || "ko2genes.pau";
#my $orgCode=$ARGV[1] || "pau";
open (IN, $inlocus) or die "cannot open $inlocus\n";
my %HoLoc2ko;
while (my $line =<IN>){
next if ($line =~ /^\s*$/);
next if ($line =~ /^#/);
chomp $line;
my ($locus,$ko)=split(/\s/,$line);
$locus =~ s/$orgCode//;
if ($ko =~ /ko:/) {
$ko =~ s/ko:// ;
}
if (defined($locus) && defined ($ko)) { # leave as array although it looks like all loci are only assigned to one ko
push @{$HoLoc2ko{$locus}},$ko;
}
}
close (IN);
print "read in ko info for\t".scalar(keys %HoLoc2ko)."\tNCBI locis\n";
#print "Loc2ko\n".Dumper(%HoLoc2ko)."\n";

最佳答案

您不需要使用 Getopt::Long::Descriptive 声明额外的标量变量。 .只需使用以下符号:

open (IN, $opt->inlocus) or die "cannot open ", $opt->inlocus, "\n";

关于perl - Getopt::Long::Descriptive - 如何声明变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19003692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com