Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在perl中访问和替换?_Perl - Fatal编程技术网

如何在perl中访问和替换?

如何在perl中访问和替换?,perl,Perl,变量中有当前服务器时间,我需要用变量中的值替换AT=2013/07/31-10:08:41。如何在Perl中替换它 get(J=tesr,T=Bp,Act=A_Ti,AT=2013/07/31-10:08:41); 使用替换运算符,有关此运算符的更多信息,请参阅: 通过简单的谷歌搜索,您可以在网上找到许多关于该操作员的教程。如果您将其作为字符串(可能来自配置文件),则可以: use warnings; use strict; my $string = 'get(J=tesr,T=Bp,Ac

变量中有当前服务器时间,我需要用变量中的值替换
AT=2013/07/31-10:08:41
。如何在Perl中替换它

get(J=tesr,T=Bp,Act=A_Ti,AT=2013/07/31-10:08:41);

使用替换运算符,有关此运算符的更多信息,请参阅:

通过简单的谷歌搜索,您可以在网上找到许多关于该操作员的教程。

如果您将其作为字符串(可能来自配置文件),则可以:

use warnings;
use strict;

my $string = 'get(J=tesr,T=Bp,Act=A_Ti,AT=2013/07/31-10:08:41);';
$string =~ /AT=(.+)\);/;
my $new_time = 'new_time';
$string =~ s/$1/$new_time/;
print $string;

当然,您必须用服务器时间替换“新时间”。下次,请先检查拼写。

这是使用另一个变量上设置的时间($new\u time)替换AT值的一天


是的,我知道替换运算符。。但在这种情况下,AT=2013/07/31-10:08:41将不是常数。。每次我都需要获取AT的值并替换。我想知道怎样去拿水!
my $str = "get(J=tesr,T=Bp,Act=A_Ti,AT=2013/07/31-10:08:41);";

my $new_time = "2013/08/01-02:05:24";

$str =~ s/(AT=)(\d{4}\/(0[1-9]|1[0-2])\/([0-2][1-9]|3[0-1])-([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9])/$1$new_time/g;

print "$str\n";