小编Thi*_*Not的帖子

如何将多个值与单个哈希键关联?

我有一个两列文件,格式如下:

CLL     s_S616447
CLL     s_S612703
MBL     s_S599565
MBL     s_S577819
UnAff   s_S509781
UnAff   s_S754982
Run Code Online (Sandbox Code Playgroud)

我想用三个键创建一个哈希,"CLL","MBL"和"UnAff".使用下面的代码,我可以将第一列指定为键,将第二列指定为值,但我不知道如何对键进行分组,这样哈希只有这三个键而不是键.文件中的每一行.

这就是我到目前为止所做的一切:

open REF, "list.txt";

my %sam_type = ();

while (<REF>) {
    chomp $_;
    @cols = split("\t", $_);
    my $type = $cols[0];
    my $sample = $cols[1];
    $sam_type{$type} = $sample;
}
Run Code Online (Sandbox Code Playgroud)

有人能引导我朝着正确的方向前进吗?

perl hash

1
推荐指数
1
解决办法
103
查看次数

为什么 Text::Balanced::extract_bracketed 不提取 LaTeX 标签内的文本?

我正在尝试使用extract_bracketedText::Balanced 解析平衡文本(实际上是用 LaTeX 编写的文本)。但是,我没有得到与以下代码的正确匹配:

use Text::Balanced qw(extract_bracketed);

my $data = 'xxx \footnote{...} yyy';
(my $ext, my $rem, my $pre) = extract_bracketed($data, '{}', '\footnote');
print "\$ext = $ext\n";
print "\$rem = $rem\n";
print "\$pre = $pre\n";
Run Code Online (Sandbox Code Playgroud)

这打印:

$ext =                                                                                                                  
$rem = xxx \footnote{...} yyy                                                                                           
$pre =
Run Code Online (Sandbox Code Playgroud)

根据文档,这个输出意味着发生了故障,但我不明白为什么。

我真正想要提取的是...,即命令的内容\footnote

为什么会发生这种情况以及如何解决它?

perl parsing latex

1
推荐指数
1
解决办法
813
查看次数

为什么我必须在我的正则表达式中逃避`]`?

运行以下内容时出错:

perl -ne 'print unless (/[A-G][\d|\s|m|#|$]/)' file
Run Code Online (Sandbox Code Playgroud)

错误:

Unmatched [ in regex; marked by <-- HERE in m/[A-G][ <-- HERE \d|\s|m|#|5.022001/ at -e line 1, <> line 1
Run Code Online (Sandbox Code Playgroud)

我通过逃避]行的末尾解决了错误:

perl -ne 'print unless (/[A-G][\d|\s|m|#|$\]/)' file
Run Code Online (Sandbox Code Playgroud)

为什么我要逃避最后一次]?什么阻止支架匹配?

我注意到所有[]比赛都不是这种情况.这是一个特例吗?

regex perl

1
推荐指数
1
解决办法
96
查看次数

if 语句中的 -e 是什么意思?

我在一些 Perl 代码中发现了以下内容:

if (! -e $options{"inPath"}){
       $logger->fatal("Directory \'$options{\"inPath\"}\' does not exist.\n");
} 
Run Code Online (Sandbox Code Playgroud)

-e声明中的作用是什么if

perl

1
推荐指数
1
解决办法
4587
查看次数

如何在 Log::Log4perl 配置文件中使用 Perl 变量?

I would like to use a Perl variable from my script in a Log::Log4perl config file. I read the documentation and found that I can use a subroutine, but I would like to do it a little bit simpler, if possible.

I want to set the filename for my appender:

log4perl.appender.av_std_LOGFILE.filename="whateverfilename.log"
Run Code Online (Sandbox Code Playgroud)

But doing this this way, it is a fixed value.

I have the filename in a variable within my script and would like to use this at runtime:

log4perl.appender.av_std_LOGFILE.filename=\ …
Run Code Online (Sandbox Code Playgroud)

perl hook log4perl

1
推荐指数
1
解决办法
889
查看次数

当我尝试使用cpan安装Perl模块时,为什么会出现"404 Not Found"和"无法更改目录"错误?

我尝试Capture::Tiny使用此命令安装:

cpan Capture/Tiny
Run Code Online (Sandbox Code Playgroud)

但安装失败,输出如下:

Reading '/root/.cpan/Metadata'
  Database was generated on Wed, 25 May 2016 08:17:02 GMT
Running make for C/C//C/Ca/Capture/Tiny
Fetching with HTTP::Tiny:
http://mirrors.dotsrc.org/cpan/authors/id/C/C//C/Ca/Capture/Tiny
HTTP::Tiny failed with code[404] message[Not Found]
Fetching with HTTP::Tiny:
http://mirrors.dotsrc.org/cpan/authors/id/C/C//C/Ca/Capture/Tiny.gz
HTTP::Tiny failed with code[404] message[Not Found]

Trying with
    /usr/bin/wget -O "/root/.cpan/sources/authors/id/C/C/C/Ca/Capture/Tiny.tmp1548"
to get
    http://mirrors.dotsrc.org/cpan/authors/id/C/C//C/Ca/Capture/Tiny
--2016-05-25 21:07:02--  http://mirrors.dotsrc.org/cpan/authors/id/C/C//C/Ca/Capture/Tiny
Resolving mirrors.dotsrc.org (mirrors.dotsrc.org)... 130.225.254.116, 2001:878:346::116
Connecting to mirrors.dotsrc.org (mirrors.dotsrc.org)|130.225.254.116|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2016-05-25 21:07:02 ERROR 404: Not Found.


    Function system("/usr/bin/wget -O …
Run Code Online (Sandbox Code Playgroud)

linux perl cpan

1
推荐指数
1
解决办法
375
查看次数

为什么我的错误'无效范围'B->"在音译操作符中",即使`tr`没有出现在我的代码中?

运行Perl脚本时出现以下错误:

在./foo.pl第249行的音译操作符中的范围"B->"无效

但是,第249行被注释掉了,我tr在代码中的任何地方都没有使用音译操作符.

这是我脚本的相关部分.第249行是# foreach (@projects),正如您所看到的,它已经被注释掉了.

# Find the project name, hardware, and version from the archive given
$project = undef;
$hardware = undef;
$version = undef;
if (defined $testfarmDB){
    my $idFile = `pwd`; 
    chomp $idFile;
    $idFile .= "/$ENV{TESTDIR}/testrun.id";
    y @filecontent = `cat $idFile`;
    $filecontent[0] =~ /(\d+)/;
    my $testRunID = $1;
    $hardware = $testfarmDB->getTestRunModelName($testRunID);
    $project = $testfarmDB->getTestRunProjectName2($testRunID);
    $version = $testfarmDB->getTestRunSWRevisionName($testRunID);
}else{
    die "Cannot connect to Database. Program terminated. \n";
}
print "   Project = $project\n";
print …
Run Code Online (Sandbox Code Playgroud)

perl transliteration

1
推荐指数
1
解决办法
261
查看次数

为什么在解码某些HTML实体而不是其他HTML实体时会出现乱码输出?

在Perl中,我试图使用HTML :: Entities解码包含数字HTML实体的字符串.一些实体工作,而"较新"实体则不工作.例如:

decode_entities('&#174;');  # returns ® as expected
decode_entities('&#8486;'); # returns Ω instead of ?
decode_entities('&#9733;'); # returns ★ instead of ?
Run Code Online (Sandbox Code Playgroud)

有没有办法在Perl中解码这些"更新"的HTML实体?在PHP中,该html_entity_decode函数似乎没有任何问题地解码所有这些实体.

perl decode html-entities

1
推荐指数
1
解决办法
86
查看次数

0
推荐指数
1
解决办法
5082
查看次数

如何将SQL查询的输出重定向到文件?

我需要一点帮助将SQL查询的输出重定向到文件.我的代码看起来像这样:

my $sth = $dbh->prepare(
    "select count(parameter2),
    parameter2 as file_type
    from KCRT_TABLE_ENTRIES where request_id = $mycrnum
    group by parameter2"
) or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";

$sth->execute > $mydir\\file_detail.txt
    or die "Can't execute SQL statement: ", $sth->errstr(), "\n";
Run Code Online (Sandbox Code Playgroud)

perl

0
推荐指数
1
解决办法
1623
查看次数