小编Ran*_*all的帖子

有没有办法打开perl中的跟踪(相当于bash -x)?

我在perl中有一个系统脚本.我需要一些等效的bash -x来确定脚本出了什么问题.有没有相当的东西?

编辑:bash -x的作用是它在评估时打印每一行.这使得调试代码只是缺少一些路径变量或文件非常容易.

debugging perl trace

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

复制没有LOCK权限的postgres数据库

我需要将postgres数据库从一个服务器复制到另一个服务器,但我拥有的凭据没有锁定数据库的权限,因此pg_dump失败.我对相关数据库有完整的读/更新/插入权限.

如何制作此数据库的副本?我并不担心不一致(它是开发服务器上的一个小型数据库,因此提取过程中出现不一致的风险很小)

[编辑]完整错误:

$ pg_dump --username=bob mydatabase > /tmp/dump.sql 
pg_dump: SQL command failed 
pg_dump: Error message from server: ERROR:  permission denied for relation sl_node 
pg_dump: The command was: LOCK TABLE _replication.sl_node IN ACCESS SHARE MODE  
Run Code Online (Sandbox Code Playgroud)

database postgresql

29
推荐指数
4
解决办法
4万
查看次数

在vim中将一对括号更改为括号的最快方法

我是vim的新手,在发现大量有趣的东西的过程中,人们可以使用这个强大的编辑器.

我需要经常做的一件事是将文本中的一对括号更改为方括号(例如更改( (a+b+c) )[ (a+b+c) ])或反之亦然.我现在通过手动改变两个字符做到这一点(,并)[].

但是,当括号之间有大量文本时,可能很难找到一对开括号和右括号,特别是因为在将第一个更改([之后,%命令将不再能够找到相应的).

我想知道是否有更好更快的方法进行此类更改?

vim matching parentheses

16
推荐指数
4
解决办法
7855
查看次数

在Perl调试器和CPAN客户端中,向上和向下箭头不再起作用

我以前在Mac OS X上使用Active Perl(v 10.7.5),然后切换到通过mac端口提供的那个(v 5.12.4).

现在,当我运行CPAN客户端或Perl调试,我无法访问使用ArrowUp和ArrowDown历史,什么是显示在提示是^[[A^[[B分别.

至少在历史工作的调试器上,我可以访问过去的命令!NUM.

debugging perl cpan arrow-keys perl5.12

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

Virtuoso Conductor的默认登录凭据

我刚刚安装了Virtuoso的opensource软件包,我正在运行名为Conductor的web gui.

它需要登录,但我不认为在安装过程中有任何设置.

这是默认的un/pass吗?如果现在,我该怎么设置?

credentials change-password virtuoso

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

与grep的非贪婪匹配

据我所知,非贪心匹配不是基本正则表达式(BRE)和扩展正则表达式(ERE)的一部分.然而,不同版本grep(BSD和GNU)的行为似乎表明其他方面.

例如,我们来看下面的例子.我有一个字符串说:

string="hello_my_dear_polo"
Run Code Online (Sandbox Code Playgroud)

使用GNU grep:

以下是hello从字符串中提取的几次尝试.

BRE尝试:

$ grep -o "hel.*\?o" <<< "$string"
hello_my_dear_polo
Run Code Online (Sandbox Code Playgroud)

输出产生整个字符串,这表明非贪婪量词对BRE不起作用.请注意,我只是逃脱了,?因为*它没有失去意义,也不需要转义.

ERE尝试:

$ grep -oE "hel.*?o" <<< "$string"
hello_my_dear_polo
Run Code Online (Sandbox Code Playgroud)

启用该-E选项也会产生相同的输出,表明非贪婪匹配不是ERE的一部分.由于我们使用ERE,因此不需要转义.

PCRE尝试:

$ grep -oP "hel.*?o" <<< "$string"
hello
Run Code Online (Sandbox Code Playgroud)

启用-PPCRE选项表明非贪婪量词是其中的一部分,因此我们得到了所需的输出hello.由于我们使用PCRE,因此不需要转义.

使用BSD grep:

以下是hello从字符串中提取的几次尝试.

BRE尝试:

$ grep -o "hel.*\?o" <<< "$string"
Run Code Online (Sandbox Code Playgroud)

使用BRE我没有得到BSD的输出grep.

ERE尝试:

$ grep -oE "hel.*?o" <<< "$string"
hello
Run Code Online (Sandbox Code Playgroud)

启用该-E选项后,我很惊讶我能够提取所需的输出.我的问题是我从这次尝试得到的输出.

PCRE尝试:

$ grep …
Run Code Online (Sandbox Code Playgroud)

regex grep bsd gnu

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

Perl推入排序数组

考虑下面的数据块,我如何维护第3个字段对数组进行排序,并继续推送项目?

$VAR1 = [
          '1111',
          'http://...',
           3       #this is one of the 3rd field mentioned above
        ];
$VARN = [
           '5555',
           'http://...',
            0
        ];
Run Code Online (Sandbox Code Playgroud)


我的代码看起来像:

my @curItem = ($item->{id}, $item->{href}, getTotal( $item->{id}) );
push @items, \@curItem;
Run Code Online (Sandbox Code Playgroud)

我发现这个模块与我需要的类似.

任何帮助赞赏.

arrays sorting perl

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

使用Perl按点分割

我通过两种方式使用split函数.第一种方式:

my $string="chr1.txt";
my @array1=split(".",$string);
print $array1[0];
Run Code Online (Sandbox Code Playgroud)

我收到此错误: Use of uninitialized value in print

当我通过第二种方式分裂时,我没有任何错误.

my @array1=split(/\./,$string);print $array1[0];
Run Code Online (Sandbox Code Playgroud)

我的第一种分裂方式不仅仅适用于点.

有人可以解释一下这背后的原因吗?

perl split

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

在制作boost.python helloword演示时不安全地使用相对rpath libboost.dylib?

最近,我正在学习boost C++库.我想用python来调用现有的C++项目.我在OSX 10.11下安装了boost brew install boost.我的python版本2.7.

我打个招呼:

char const* greet()
{
    return "hello, world";
}

#include <boost/python.hpp>

BOOST_PYTHON_MODULE(hello)
{
    using namespace boost::python;
    def("greet", greet);
}
Run Code Online (Sandbox Code Playgroud)

和Makefile:

PYTHON_VERSION = 2.7
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)

# location of the Boost Python include files and library
#  
BOOST_INC = /usr/local/include
BOOST_LIB = /usr/local/lib
#   
# compile mesh classes
TARGET = hello

$(TARGET).so: $(TARGET).o
    g++ -shared -Wl $(TARGET).o -L$(BOOST_LIB) -lboost_python -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION) -o $(TARGET).so

$(TARGET).o: $(TARGET).c
    g++ -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).c
Run Code Online (Sandbox Code Playgroud)

然而,在我跑完make …

c++ python macos boost

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

使用cpanm安装Perl模块

也许这是一个愚蠢的问题?如果我安装一个像File使用的模块

cpanm File
Run Code Online (Sandbox Code Playgroud)

将它安装下的一切File,喜欢File:Listing等?

cpan perl-module cpanm

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

cpanm 安装 Perl 模块的默认路径是什么?

在我使用cpanm在“新”(对我而言)系统上安装一些 Perl 模块之前,我想知道默认情况下它们将安装在哪里。

我没有看到任何类型的试运行选项,这正是我所希望的。

perl -V 包括这个 %ENV 和 @INC 信息:

%ENV:
  PERL5LIB="/home/randall/perl5/lib/perl5"
  PERL_HOMEDIR="1"
  PERL_LOCAL_LIB_ROOT="/home/randall/perl5"
  PERL_MB_OPT="--install_base /home/randall/perl5"
  PERL_MM_OPT="INSTALL_BASE=/home/randall/perl5"
@INC:
  /home/randall/perl5/lib/perl5
  /usr/local/lib64/perl5
  /usr/local/share/perl5
  /usr/lib64/perl5/vendor_perl
  /usr/share/perl5/vendor_perl
  /usr/lib64/perl5
  /usr/share/perl5
Run Code Online (Sandbox Code Playgroud)

这是否定义了行为,还是有其他考虑?具体来说,cpanm 的文档包括:

-l, --local-lib
    Sets the local::lib compatible path to install modules to. You don't
    need to set this if you already configure the shell environment
    variables using local::lib, but this can be used to override that as
    well.
Run Code Online (Sandbox Code Playgroud)

但它并没有指出哪些环境变量是重要的。

default perl-module cpanm

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

Virtuoso ISQL数据导入不能是stat文件

isql-vt(Virtuoso的Ubuntu名称isql)中,我试图导入测试.ttl文件,但得到错误"无法统计文件":

SQL> DB.DBA.TTLP(file_to_string_output('./scratch/ttl/granule.ttl'),'','http://origin.mytest.org/');

*** Error 42000: [Virtuoso Driver][Virtuoso Server]FA112: Can't stat file './scratch/ttl/granule.ttl', error (2) : No such file or directory
Run Code Online (Sandbox Code Playgroud)

但是,文件肯定存在; 我甚至cat可以:

SQL> !cat ./scratch/ttl/granule.ttl;
@prefix datacite: <http://purl.org/spar/datacite/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
<http://0.0.0.0:3000/granule/MOD09.A2016278.0110.006.2016279074214.hdf>
   datacite:identifier "MOD09.A2016278.0110.006.2016279074214.hdf";
   prov:wasGeneratedBy <http://0.0.0.0:3000/run/MODAPS_456056327>;
   a prov:entity .

SQL> 
Run Code Online (Sandbox Code Playgroud)

为什么DB.DBA.TTLP命令说不能统计它?

file-access virtuoso

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

如何使用Term :: ReadLine来检索命令历史记录?

我有以下脚本,这与文档中的概要段落中的示例几乎相同.

use strict;
use warnings;
use Term::ReadLine;

my $term = Term::ReadLine->new('My shell');
print $term, "\n";
my $prompt = "-> ";

while ( defined ($_ = $term->readline($prompt)) ) {
   print $_, "\n";
   $term->addhistory($_);
}
Run Code Online (Sandbox Code Playgroud)

它执行时没有错误,但不幸的是,即使我单击向上箭头,我也只能得到^[[A并且没有历史记录.我错过了什么?

print $term语句打印Term::ReadLine::Stub=ARRAY(0x223d2b8).

因为我们在这里,我注意到它打印出下划线的提示...但我在文档中找不到任何可能阻止它的东西.有什么办法可以避免吗?

perl readline arrow-keys

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