小编Wak*_*nka的帖子

TCL/Expect - $argv VS $::argv VS {*}$argv

以下变量之间有什么区别:

$argv
$::argv
{*}$argv
Run Code Online (Sandbox Code Playgroud)

前两个可以通过puts命令打印,它们返回以下输出:

param0 param1 {param 2} param3
param0 param1 {param 2} param3
Run Code Online (Sandbox Code Playgroud)

传递给脚本的参数是:

param0 param1 "param 2" param3
Run Code Online (Sandbox Code Playgroud)

最后一个结果出现错误:

wrong # args: should be "puts ?-nonewline? ?channelId? string"
    while executing
"puts {*}$argv"
Run Code Online (Sandbox Code Playgroud)

我使用以下代码在该领域做了一些研究:

if {[array exists $argv]} {
  puts "\$argv IS ARRAY"
} else {
  puts "\$argv IS NOT AN ARRAY"
}

if {[string is list $argv]} {
  puts "\$argv IS LIST"
} else {
  puts "\$argv IS NOT LIST"
}

if {[array exists $::argv]} …
Run Code Online (Sandbox Code Playgroud)

tcl expect

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

键盘中断与python的多处理池和映射功能

我发现这篇文章解释了如何使用 ctr+c 终止正在运行的多处理代码。以下代码完全正常工作(可以使用 ctrl+c 终止它):

#!/usr/bin/env python

# Copyright (c) 2011 John Reese
# Licensed under the MIT License

import multiprocessing
import os
import signal
import time

def init_worker():
    signal.signal(signal.SIGINT, signal.SIG_IGN)

def run_worker():
    time.sleep(15)

def main():
    print "Initializng 5 workers"
    pool = multiprocessing.Pool(5, init_worker)

    print "Starting 3 jobs of 15 seconds each"
    for i in range(3):
        pool.apply_async(run_worker)

    try:
        print "Waiting 10 seconds"
        time.sleep(10)

    except KeyboardInterrupt:
        print "Caught KeyboardInterrupt, terminating workers"
        pool.terminate()
        pool.join()

    else:
        print "Quitting normally"
        pool.close()
        pool.join() …
Run Code Online (Sandbox Code Playgroud)

python python-multiprocessing

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

如果使用分组元字符,则搜索和替换regexp会提供两个不同的输出

我从搜索获得不同的输出并替换perl中的regexp,这取决于我是否使用到位替换(sed替代)或常规搜索替换,还取决于我是否使用\1$1:

??> cat test1.txt 
orig.avg.10

??> cat test2.txt 
orig.avg.10

# EXPECTED
??> cat test1.txt | perl -lne '$_ =~ s/(avg\.[0-9]+)/$1\.vec/; print $_'
orig.avg.10.vec

# EXPECTED
??> cat test1.txt | perl -lne '$_ =~ s/(avg\.[0-9]+)/\1\.vec/; print $_'
orig.avg.10.vec

# EXPECTED
??> perl -p -i.bak -e "s/(avg\.[0-9]+)/\1\.vec/" test2.txt
??> cat test2.txt
orig.avg.10.vec

# UNEXPECTED
??> perl -p -i.bak -e "s/(avg\.[0-9]+)/$1\.vec/" test1.txt
??> cat test1.txt
orig..vec
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

regex perl sed

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

Bioconductor与CRAN

今天我发现除了CPAN之外还有另一个存储库.该存储库是Bioconductor.到目前为止,我注意到Bioconductor的安装过程与传统的CRAN相比略有不同install.packages().当我想使用Bioconductor的一些包装时,我应该担心吗?是否有可能陷入一些依赖性问题(如混合使用例如ubuntu/debian存储库等)等?我问,因为例如说:

如果你不介意使用bioconductor包,那么,你可以使用...

Bioconductor或其他可能的存储库有什么问题?

r repository bioconductor cran

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

使用调试符号和 cmake 编译项目的正确方法

CMAKE_BUILD_TYPE当我想获取调试或发布项目构建时,建议将这里作为参数传递给 cmake。我正在尝试用 cmake编译libharu,我想用调试符号编译它。我搜索了libharu 中包含的 CMakeLists.txt 以查找以下字符串:

CMAKE_BUILD_TYPE
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_DEBUG
Run Code Online (Sandbox Code Playgroud)

但我什么也没找到。我的问题是,指定libharu的 CMakeLists.txtCMAKE_BUILD_TYPE何时没有提及它是否有意义?如果没有,我如何使用调试符号编译libharu

PS:我注意到使用 cmake 为 Visual Studio 2013 生成的项目设置了 Debug/Win32,这是否足够?在 CMakeLists.txt 中的何处指定了此信息?

PPS:我想这个问题在很大程度上取决于特定的项目,但一般来说有什么方法可以做到这一点吗?我的意思是,CMAKE_BUILD_TYPE=Debug总是创建 Debug 版本还是我应该注意其他一些事情?

谢谢

cmake libharu cmake-gui

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

re.finditer 有一定的长度,但我无法迭代它

以下代码块有效,对我来说似乎相当合法。字符串中有TP两次TP Tutorials Point TP,因此匹配数应为 2。此外,对该列表的迭代也应该有效。

s = 'TP Tutorials Point TP'

out = re.findall(r'TP', s)

assert len(list(out)) == 2

# this loop will print 2 times matched string
for m in out:
    print(m)
Run Code Online (Sandbox Code Playgroud)

但这是怎么回事?

s = 'TP Tutorials Point TP'

out = re.finditer(r'TP', s)

# seems OK so far
assert len(list(out)) == 2

# !!! no output here !!!
for m in out:
    print(m)
Run Code Online (Sandbox Code Playgroud)

为什么我无法迭代finditer方法的返回输出?在下一篇文章中表明,这finditer也应该有效。我的Python版本:3.8.10

python python-re

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

perl - 调用ref没有返回任何内容

有人可以解释为什么调用ref没有返回任何东西?

[pista@HP-PC ~]$ perl -wlae '$var=1; print ref($var)'

[pista@HP-PC ~]$ perl -wlae '@var=1; print ref(@var)'

[pista@HP-PC ~]$ perl -v

This is perl 5, version 14, subversion 3 (v5.14.3) built for x86_64-linux-thread-multi

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" …
Run Code Online (Sandbox Code Playgroud)

perl

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

Perl - 将localtime的输出存储到哈希中

在perl中,我可以使用以下命令序列获得当前秒数:

my @time = ($sec,$min,$hour,$day,$mon,$year_1900,$wday,$yday,$isdst)=localtime;
print $time[0]
Run Code Online (Sandbox Code Playgroud)

有没有相当于这个,但使用哈希?所以可以输入这样的东西:

print $time{"sec"} 
Run Code Online (Sandbox Code Playgroud)

我试过了:

my %time= ("sec","min","hour","day","mon","year_1900","wday","yday","isdst")=localtime;
print $time{"sec"}
Run Code Online (Sandbox Code Playgroud)

但它以下列错误结束:

Can't modify constant item in list assignment at -e line 1, near "localtime;"
Execution of -e aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)

谢谢

perl hashmap localtime

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

分裂函数的奇怪行为

有人可以解释以下输出:

为什么有两个$ VAR1变量,如果它是具有更多元素的数组,其中是$ VAR2?

$ echo -e "a:b:c\n" | perl -lne 'use Data::Dumper; @a = split(":", $_); print Dumper \@a'
$VAR1 = [
          'a',
          'b',
          'c'
        ];

$VAR1 = [];
Run Code Online (Sandbox Code Playgroud)

Seme输出如上所述而不是引用是打印数组,没有其他元素,因为它是以前.

$ echo -e "a:b:c\n" | perl -lne 'use Data::Dumper; @a = split(":", $_); print Dumper @a'
$VAR1 = 'a';
$VAR2 = 'b';
$VAR3 = 'c';
Run Code Online (Sandbox Code Playgroud)

'undef'来自哪里?又为什么奇怪的$ VAR1?

$ echo -e "a:b:c\n" | perl -lne 'use Data::Dumper; @a = split(":", $_); $b = $a[0]; print Dumper $b'
$VAR1 = 'a'; …
Run Code Online (Sandbox Code Playgroud)

bash perl

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

从R中的每个列表元素中减去值

我需要从R.每个列表元素在减去指定的值,被提到的文章,对于这样的任务apply系列函数来代替循环.我试过以下:

# Define list
> a = 1:20

# Substraact this from each element
> substract_me = 5

# Function for substracting
> substract = function(x,y) { ret = x-y; return(ret) }

# The problem is that I do not know how to access the current array element and pass it to substract function
lapply(a, substract)
Run Code Online (Sandbox Code Playgroud)

这里提到匿名函数也可以使用,但它对我没有用,我得到语法错误.事实上,它看起来就像语法糖一样.问题仍然存在,我在使用lapply函数时需要一些占位符或其他东西,所以我可以访问当前的list元素:

lapply(a, function([WHAT TO ADD HERE???],substract_me) substract([WHAT TO ADD HERE???],substract_me))
Run Code Online (Sandbox Code Playgroud)

可能是相关的,但我没有弄清楚过去的代码片段是如何工作的.

r

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

包含标题后显示生成的c/c ++文件(在转换为机器语言之前)

这个关于头文件和源文件的答案说:

编译器会看到一个大的源(.cpp)文件及其正确包含的标头.源文件是将编译为目标文件的编译单元.

有可能以某种方式查看这个大的.cpp(.c)文件吗?如果是,那么如何在Linux(gcc)和Windows(VisualStudio)平台上执行此操作.

PS:我已经试过在Visual Studio/P选项(关于Solution Explorer中,转到属性的文件上单击右键;配置属性- > C/C++ - >预处理器- >预处理到文件- > [YES/P] )但是我已经获得了几个*.i文件,这些文件看起来不像c ++(可能是c ++,但有许多模板,内存分配定义等).我所指的答案是谈论"一个大的.cpp文件".所以我假设只有#include指令会被相应的文件替换,或者我错了,*.i输出是我被要求的?

c c++

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

为什么这个Perl函数似乎只处理它的一些参数?

为什么

my $i=0;
my @arr=();

sub readall {
    foreach (@_) {
        $arr[$i] = shift @_;
        $i++;
    }
}

readall(1, 2, 3, 4, 5);
print "@arr"
Run Code Online (Sandbox Code Playgroud)

my $i=0;
my @arr=();

sub readall {
    foreach (@_) {
        $arr[$i] = shift @_;
        print $arr[$i];
        $i++;
    }
}

readall(1, 2, 3, 4, 5);
Run Code Online (Sandbox Code Playgroud)

只打印三个参数readall

为什么这个函数看起来应该表现得一样,处理所有五个参数?

sub readall {
    foreach (@_) {
        print $_;
    }
}

readall(1, 2, 3, 4, 5);
Run Code Online (Sandbox Code Playgroud)

这也读取了所有五个(但确实按照不同的原则操作):

my @arr=();

sub readall {
    push(@arr, @_);
}

readall(1, 2, …
Run Code Online (Sandbox Code Playgroud)

perl arguments argument-passing

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

如何在perl系统函数中使用两个管道并防止shell扩展?

如果将多个参数传递给perl的系统函数,则shell扩展将不起作用:

# COMMAND
$ perl -e 'my $s="*"; system("echo", "$s" )'

# RESULT
*
Run Code Online (Sandbox Code Playgroud)

如果命令作为一个参数传递,那么扩展将起作用:

# COMMAND
$ perl -e 'my $s="echo *"; system("$s")'

# RESULT
Desktop Documents Downloads
Run Code Online (Sandbox Code Playgroud)

系统功能还允许使用多个命令并使用管道连接它们.这仅在参数作为一个命令传递时有效:

# COMMAND
$ perl -e 'my $s="echo * | cat -n"; system("$s")'

# RESULT
1 Desktop Documents Downloads
Run Code Online (Sandbox Code Playgroud)

如何组合提到的命令并使用两个管道并防止shell扩展?

我试过了:

# COMMAND
$ perl -e 'my $s="echo"; system("$s", "* | cat -n")'

# RESULT
* | cat -n
Run Code Online (Sandbox Code Playgroud)

但由于我上面描述的原因(多个参数未扩展),这不起作用.我想要的结果是:

1 *
Run Code Online (Sandbox Code Playgroud)

编辑:我实际面临的问题是当我使用以下命令时:

system("echo \"$email_message\" | mailx -s \"$email_subject\" $recipient");
Run Code Online (Sandbox Code Playgroud)

然后扩展$ …

shell perl system pipe variable-expansion

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