2

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

$ 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";
4

1 回答 1

3

您不需要使用Getopt::Long::Descriptive声明其他标量变量。只需使用以下符号:

open (IN, $opt->inlocus) or die "cannot open ", $opt->inlocus, "\n";
于 2013-09-25T12:32:28.257 回答