小编Gur*_*uru的帖子

Perl:特殊数组@_真的不是别名吗?

@_传递给函数的所有参数都存在的特殊数组实际上是传递的参数的别名.因此,我们直接对这个特殊数组进行的任何更改都@_将反映在主要数据中.这很清楚.

#!/usr/bin/perl

use warnings;
use strict;

$\="\n";

sub func {
        print \@_;
        $_++ for(@_);
}

my @arr=(2..4);
print \@arr;
func(@arr);
print "@arr";
Run Code Online (Sandbox Code Playgroud)

对于上面的程序,我期望引用@arr@_指向相同的位置,因为它是别名.但事实并非如此.

在运行上面:

ARRAY(0x1b644d0)
ARRAY(0x1b644e0)
3 4 5
Run Code Online (Sandbox Code Playgroud)

如果他们指向两个不同的位置,那么所做的更改@_是如何反映的@arr

我看错了吗?请指教.

perl

12
推荐指数
2
解决办法
1014
查看次数

将文本文件拆分为多个文件

我有一个大文本文件,每个摘要之间有1000行摘要,空行.我想将此文件拆分为1000个文本文件.我的文件看起来像

16503654    Three-dimensional structure of neuropeptide k bound to dodecylphosphocholine micelles.      Neuropeptide K (NPK), an N-terminally extended form of neurokinin A (NKA), represents the most potent and longest lasting vasodepressor and cardiomodulatory tachykinin reported thus far.  

16504520    Computer-aided analysis of the interactions of glutamine synthetase with its inhibitors.        Mechanism of inhibition of glutamine synthetase (EC 6.3.1.2; GS) by phosphinothricin and its analogues was studied in some detail using molecular modeling methods. 
Run Code Online (Sandbox Code Playgroud)

unix bash awk

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

Spring JPA 分页 - 获取并更新

我的数据库表中有 100 条具有特定状态 X 的记录。我想使用分页(例如页大小 10)来获取所有记录。在处理获取的记录期间,在某些情况下,记录将更新为状态 Y。但是,如果不满足某些条件,则不会更新状态并跳过记录。我正在使用 Spring Data JPA 的可分页对象来执行此操作。

Pageable  pageable =  PageRequest.of(0, 10);
Run Code Online (Sandbox Code Playgroud)

由于对列的更新,我认为每次我在第0页本身中获取下一组记录。问题是:因为有些记录可以保留而不更新,比如说当 10 条记录没有更新时,这 10 条记录继续出现在第 0 页中,我永远无法获取剩余的记录。

请建议在涉及更新时如何使用分页获取记录。

spring spring-data-jpa

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

如何评估re.sub中的替换部件?

我有一个字符串说“Alex 28”。现在,我想提取数字 28 并使用正则表达式将其加 2。

在 Perl 中,我可以这样得到它:

#!/usr/bin/perl
use strict;
use warnings;

my $str='Alex 28';
$str=~s/(\d+)/$1+2/e;
Run Code Online (Sandbox Code Playgroud)

为了在 Python 中实现这一点,我尝试了以下方法:

#!/usr/bin/python

import re

str = 'Alex 28'

match=re.sub(r'(\d+)',r'\g<1>',str)
Run Code Online (Sandbox Code Playgroud)

如何将 2 添加到\g<1>已获取的 ' ' 上?我尝试使用 int 函数,它不起作用。请帮忙。

版本:Python 2.7.3

python regex

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

标签 统计

awk ×1

bash ×1

perl ×1

python ×1

regex ×1

spring ×1

spring-data-jpa ×1

unix ×1