我有一个关于Perl qr运算符的问题:
Run Code Online (Sandbox Code Playgroud)#!/usr/bin/perl -w &mysplit("a:b:c", /:/); sub mysplit { my($str, $pattern) = @_; my @arr = split $pattern, $str; print "@arr\n"; }
结果是:
在./test.pl第3行的模式匹配(m //)中使用未初始化的值$ _.
在./test.pl第7行的regexp编译中使用未初始化的值$ pattern.
但是,当我使用:&mysplit("a:b:c", qr/:/);,它没关系.
那么,我想知道qr//和之间的区别是m//什么?
为什么$_这里有关系?
为什么在这种情况下还可以split /:/, "a:b:c";呢?
先感谢您!
我遇到了一段Python 3代码:
def gen():
try:
while True:
yield 1
finally:
print("stop")
print(next(gen()))
Run Code Online (Sandbox Code Playgroud)
运行它之后,我首先想到的输出应该是:
def gen():
try:
while True:
yield 1
finally:
print("stop")
print(next(gen()))
Run Code Online (Sandbox Code Playgroud)
但实际上结果是:
1
Run Code Online (Sandbox Code Playgroud)
怎么会这样 引擎盖下发生了什么?
如果我运行for i in gen(): print(i),将会出现一个无限循环,这正是我所期望的。for和next这里和有什么不一样?
我有关于Erlang功能的问题.查看Erlang shell中的代码:
Run Code Online (Sandbox Code Playgroud)1> F1 = fun() -> timer:sleep(1000) end. #Fun<erl_eval.20.111823515> 2> F2 = fun() -> io:format("hello world~n", []) end. #Fun<erl_eval.20.111823515>
F1和F2是不同的,但为什么他们都有标识符#Fun<erl_eval.20.111823515>?这些神奇数字意味着什么?
ERTS手册中有一段说:
When interpreting the data for a process, it is helpful to know that anonymous
function objects (funs) are given a name constructed from the name of the
function in which they are created, and a number (starting with 0) indicating
the number of that fun within that function.
Run Code Online (Sandbox Code Playgroud)
我也抓不住这一段的含义,请你解释一下吗?
我对OSGi中Java ClassLoader的用法有疑问.
我写了两个OSGi包,即服务器包和客户端包.
在服务器包中,我实现了BundleActivator,如:
public class Activator implements BundleActivator {
public void start(BundleContext context) {
System.out.println("[Server:Activator.java:26] " + Activator.class.getClassLoader());
context.registerService(HelloService.class, new HelloService(), null);
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
Run Code Online (Sandbox Code Playgroud)
在客户端捆绑中,我实现了BundleActivator,如:
public class Activator implements BundleActivator {
public void start(BundleContext context) {
ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class);
HelloService service = context.getService(ref);
System.out.println("[Client:Activator.java:48] " + HelloService.class.getClassLoader());
System.out.println("[Client:Activator.java:49] " + Activator.class.getClassLoader());
}
public void stop(BundleContext context) {
System.out.println("Stopping the bundle");
}
}
Run Code Online (Sandbox Code Playgroud)
当我启动OSGi时,控制台输出:
[服务器:Activator.java:26] org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@56b161a [osgi-server:1.0.0(id = 54)] [客户端:Activator.java:48] …
我有Perl local语法的问题.
代码如下:
#!/usr/bin/perl -w
&outer;
sub outer {
local $lvar = 'local';
&inner;
}
sub inner {
print "lvar: $lvar\n";
}
Run Code Online (Sandbox Code Playgroud)
如果我运行代码,它输出:
lvar: local
Run Code Online (Sandbox Code Playgroud)
但如果代码修改如下:
#!/usr/bin/perl -w
use strict;
&outer;
sub outer {
local $lvar = 'local';
&inner;
}
sub inner {
print "lvar: $lvar\n";
}
Run Code Online (Sandbox Code Playgroud)
然后,出现错误:
Global symbol "$lvar" requires explicit package name at ./test.pl line 7.
Global symbol "$lvar" requires explicit package name at ./test.pl line 12.
Execution of ./test.pl aborted due to compilation errors.
Run Code Online (Sandbox Code Playgroud)
我在这里很困惑.我想最小化范围 …
我有一个关于 C 中 I/O 编程中的缓冲区的问题。
例如,总是说fwrite是一个缓冲的 i/o,而write是一个无缓冲的 i/o。我的理解是这里的“缓冲”是在应用程序层,我认为在内核级别,它们都有一个缓冲区。从 APUE,我看到:
UNIX 系统的传统实现在内核中具有缓冲区缓存或页面缓存,大多数磁盘 I/O 都通过这些缓存。当我们将数据写入文件时,数据通常由内核复制到其中一个缓冲区中,并排队等待稍后写入磁盘。这称为延迟写入。
我对吗?所以我做了一个实验:
int main() {
char *fname = "helloworld";
char content[] = "abcdefg";
int fd = open(fname, O_WRONLY | O_CREAT);
int flag = fcntl(fd, F_GETFL);
flag &= ~O_SYNC;
fcntl(fd, F_SETFL, flag);
write(fd, content, 3);
sleep(100);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我认为睡眠期间应该没有任何输出,但事实恰恰相反。
我有什么误解吗?
选项-Y,-2和-R在tshark迷惑我很长一段时间.
在我阅读了本手册之后,我知道-Y用于单通滤波器,-2用于2通滤波器(如果在第一次通过滤波器结束之前我们无法得到一些信息)
但我仍然无法理解之间有什么区别-2 -Y 'blabla'和-2 -R 'balabala'和-2 -Y 'blalal' -R 'blala'
我也做了一个让我疯狂的实验:
tshark -n -r test.pcap -2 -R 'frame.number > 0'
1 0.000000 10.140.28.17 -> 10.74.68.58 TCP 80 62276 > 8989 [SYN, ECN, CWR] Seq=0 Win=65535 Len=0 MSS=1460 WS=32 TSval=330325315 TSecr=0 SACK_PERM=1
2 0.000056 10.74.68.58 -> 10.140.28.17 TCP 76 8989 > 62276 [SYN, ACK, ECN] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=2078759468 TSecr=330325315 …Run Code Online (Sandbox Code Playgroud) 我使用 Netty 实现带有安全套接字的服务器。我的 sslHandler 代码是:
SslHandler sslHandler = SslContextBuilder
.forServer(certFile, keyFile)
.trustManager(trustFile)
.clientAuth(ClientAuth.REQUIRE)
.build()
.newHandler(channel.alloc());
Run Code Online (Sandbox Code Playgroud)
trustFile是一个 File 对象,其中包含大约 700 条证书文本,例如:
-----开始证书----- MIIEHDCCAwSgAwiBAgIJAOR6+3G8C6f7MA0GCSqGSIb3DQEBCwUAMIGNMQswCQYD VQQGEwJVUzESMBAGA1UECAwJQ2FsaWZvbWlhMRwwGgYDVQQKDBNDaXNjbyBTeXN0 ................................ ............................ igHdyc519KbYSMfhuM9gXw35LPmFWStBGYikBcMZJ1WmWxb/eZOK1SMjVQ/L/JVg -----结束证书-----
当我连接服务器时
curl -k -v -E client.pem --key client.key.pem --cacert rootCA.pem https://10.140.28.33:31069
弹出异常:
11:00:18.636 [nioEventLoopGroup-3-2] WARN io.netty.channel.DefaultChannelPipeline - An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException: java.lang.RuntimeException: Field length overflow, the field …Run Code Online (Sandbox Code Playgroud)