-8

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

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

3 回答 3

0

那是使用在另一个变量上设置的时间(在本例中为 $new_time )替换 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";
于 2013-07-30T17:44:54.823 回答
0

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

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_time”替换为您的服务器时间。下次请先检查您的拼写。

于 2013-07-30T13:40:30.757 回答
0

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

http://perldoc.perl.org/functions/s.html

通过简单的 google 搜索,您可以在网上找到许多关于此运算符的教程。

于 2013-07-30T13:18:05.497 回答