- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了一个函数,这里是:
use strict;
use warnings;
use feature 'say';
use JSON;
use utf8;
sub process {
my %IDs = ( "User awx01 logged in." => 1001 );
my %levels = ( INFO => 4 );
my $data = do { local $/; <DATA> };
# read in all the data, even though it looks
my $decoded = decode_json( $data );
$decoded->{Message} = decode_json( $decoded->{Message} );
say rec2msg($decoded);
sub rec2msg {
my $r = shift;
$r->{Message}{message} =~ /(\w+) (\w+) (.+)/;
my($user,$msg) = ($2,"$1 $3");
my $ID = $IDs{$r->{Message}{message}};
my $level = $levels{$r->{Message}{level}};
my $out = "$r->{Message}{'@timestamp'} host CEF:0|OpenSource|AWX|7.0.0|$ID|$msg|$level|src=127.0.0.1 dst=$r->{MessageSourceAddress} duser=$user";
return $out;
}
}
__DATA__
{"MessageSourceAddress":"192.168.81.20","EventReceivedTime":"2020-02-06 11:55:14","SourceModuleName":"udp","SourceModuleType":"im_udp","SyslogFacilityValue":1,"SyslogFacility":"USER","SyslogSeverityValue":5,"SyslogSeverity":"NOTICE","SeverityValue":2,"Severity":"INFO","EventTime":"2020-02-06 11:55:14","Hostname":"192.168.81.20","Message":"{\"@timestamp\": \"2020-02-06T08:55:52.907Z\", \"message\": \"User awx01 logged in.\", \"host\": \"awxweb\", \"level\": \"INFO\", \"logger_name\": \"awx.api.generics\", \"stack_info\": null, \"type\": \"other\", \"cluster_host_id\": \"awx-contr-01\", \"tower_uuid\": \"333b4131-495f-4460-8e4b-890241a9d73d\"}"}
2021-02-06T08:55:52.907Z host CEF:0|OpenSource|AWX|7.0.0|1001|User logged in.|4|src=127.0.0.1 dst=192.168.81.20 duser=awx01
use strict;
use warnings;
use feature 'say';
use JSON;
use utf8;
sub process {
my %IDs = ( "User awx01 logged in." => 1001 );
my %levels = ( INFO => 4 );
my $data = do { local $/; <DATA> };
# read in all the data, even though it looks
my $decoded = decode_json( $data );
$decoded->{Message} = decode_json( $decoded->{Message} );
say rec2msg($decoded);
local *rec2msg = sub {
my $r = shift;
$r->{Message}{message} =~ /(\w+) (\w+) (.+)/;
my($user,$msg) = ($2,"$1 $3");
my $ID = $IDs{$r->{Message}{message}};
my $level = $levels{$r->{Message}{level}};
my $out = "$r->{Message}{'@timestamp'} host CEF:0|OpenSource|AWX|7.0.0|$ID|$msg|$level|src=127.0.0.1 dst=$r->{MessageSourceAddress} duser=$user";
return $out;
}
return rec2msg();
}
__DATA__
{"MessageSourceAddress":"192.168.81.20","EventReceivedTime":"2020-02-06 11:55:14","SourceModuleName":"udp","SourceModuleType":"im_udp","SyslogFacilityValue":1,"SyslogFacility":"USER","SyslogSeverityValue":5,"SyslogSeverity":"NOTICE","SeverityValue":2,"Severity":"INFO","EventTime":"2020-02-06 11:55:14","Hostname":"192.168.81.20","Message":"{\"@timestamp\": \"2020-02-06T08:55:52.907Z\", \"message\": \"User awx01 logged in.\", \"host\": \"awxweb\", \"level\": \"INFO\", \"logger_name\": \"awx.api.generics\", \"stack_info\": null, \"type\": \"other\", \"cluster_host_id\": \"awx-contr-01\", \"tower_uuid\": \"333b4131-495f-4460-8e4b-890241a9d73d\"}"}
最佳答案
使用嵌套的命名子例程有点不寻常。
该错误消息的 The documentation 提供了一些建议:
Variable "%s" will not stay shared
(W closure) An inner (nested) named subroutine is referencing a lexical variable defined in an outer named subroutine.
When the inner subroutine is called, it will see the value of the outer subroutine's variable as it was before and during the first call to the outer subroutine; in this case, after the first call to the outer subroutine is complete, the inner and outer subroutines will no longer share a common value for the variable. In other words, the variable will no longer be shared.
This problem can usually be solved by making the inner subroutine anonymous, using the sub {} syntax. When inner anonymous subs that reference variables in outer subroutines are created, they are automatically rebound to the current values of such variables.
关于perl - 使用子程序时出现错误 "variable will not stay shared",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61186639/
我有一个包含很多工作表和几个宏的工作簿。当我进入 VBA 并尝试将新的 Sub 写入 ThisWorkbook 模块时,我看到: "This will reset your project, proc
1、函数定义 子程序即一段分离的代码,它可以使减少重复代码且程序易读.perl中,子程序可以出现在程序的任何地方.但一般放在程序的开始或结尾. 复制代码 代码如下:
1、定义 子程序即执行一个特殊任务的一段分离的代码,它可以使减少重复代码且使程序易读。PERL中,子程序可以出现在程序的任何地方。定义方法为: &n
如何将 deck(52) 数组从 Newgame 函数传递到 deckshuffle 函数 FUNCTION newgame 'New game RANDOMIZE TIMER CA
有没有办法在后台运行 perl 子程序?我环顾四周,看到了一些关于线程的提及,但看到一个例子会有所帮助,或者为我指明正确的方向。谢谢。 想跑run_sleep在后台。 #!/usr/bin/perl
情况 我正在创建一个简单的模板文件,该文件将有助于创建 future 的脚本,以便在 *nix 系统上通过命令行执行各种任务。作为其中的一部分,我可能会要求用户输入需要根据源代码中提供的正则表达式进行
我想将以下变量传递给子程序 mySubroutine,$name, $age然后是这个多维数组: $name = "jennifer"; $age = 100; $list[0][0] = "TEST
据我所知,VB6不支持继承,但它支持接口(interface)。我正在尝试创建一个重载子例程,将其信息传递给基类的同名子例程。 Sub Main() Dim Student1 as New S
这个问题已经有答案了: Dynamic Function Calls in Excel VBA (1 个回答) 已关闭 8 年前。 这是我的测试代码 Sub dotask() Dim qusu
我正在编写一个本质上是静态的函数。我想将它插入到模板工具包中,它会传递类名。本质上,它正在做 ClassName->function( $args.. ) 但我希望它做类似的事情 ClassName:
我创建了一个小示例程序来检查子例程系统调用。 package main func print() { } func main() { go print() } go 子程序的 straces
我是该网站的新手,这看起来可能是获得一些提示和帮助(如果有的话)的地方。 我正在学习“C 调用 Fortran 子程序”,我对 C 有一定的了解,但对 Fortran 了解不多。 优点:我看过一些例子
是否有一种方法/功能可以为所有可用的 Mojolicious 路由编写自动启动子程序/方法? 也许是一个自动助手,但我还不知道如何去做。 我认为这对于为几乎所有可用路由初始化数据库连接 $self->
我试图在不实例化对象的情况下从类中调用原型(prototype)函数。我的类(class) MyClass 的一个例子: package MyClass; use strict; use warnin
我正在尝试从 C 调用 FORTRAN 函数 我的问题是: 如果 fortRoutine 是我的 fortran 子例程的名称,那么我从 C 调用它作为 fortRoutine_。如果 fortRou
我可以调用编译这个 fortran 代码 'test.f90' subroutine test(g,o) double precision, intent(in):: g double precisi
我制作了一个 Perl 模块 MyModule.pm 它有一些我想在 shell 脚本中调用的子例程 getText。我尝试了以下方式,但它给出了错误; SEC_DIR=`perl -MMyModul
我用 CommaIde 打开了这个简单的脚本: #!/usr/bin/env perl6 my $str = 'foobar'; say $str; IDE 突出显示了带有错误的“说”一词: Subr
我基本上有一个存储有数字 1-6(例如垄断)的立方体 vector > cube; 看起来像这样: 0300 5126 0400 我有将它倒转的代码: short tmp=cube[0][1]; cu
我必须在两个文件中创建一个 surbroutine,我在构建项目时遇到问题,出现错误: undefined reference to c 我不知道发生了什么,我正在尝试发送 C[0] 内存方向,这就是
我是一名优秀的程序员,十分优秀!