#最近读的东西

#perl 用法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[2024/01/21 9:47:32] mbp ➜  ~  perl -h

Usage: perl [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into @F)
-C[number/list] enables the listed Unicode features
-c check syntax only (runs BEGIN and CHECK blocks)
-d[:debugger] run program under debugger
-D[number/list] set debugging flags (argument is a bit mask or alphabets)
-e program one line of program (several -e's allowed, omit programfile)
-E program like -e, but enables all optional features
-f don't do $sitelib/sitecustomize.pl at startup
-F/pattern/ split() pattern for -a switch (//'s are optional)
-i[extension] edit <> files in place (makes backup if extension supplied)
-Idirectory specify @INC/#include directory (several -I's allowed)
-l[octal] enable line ending processing, specifies line terminator
-[mM][-]module execute "use/no module..." before executing program
-n assume "while (<>) { ... }" loop around program
-p assume loop like -n but print line also, like sed
-s enable rudimentary parsing for switches after programfile
-S look for programfile using PATH environment variable
-t enable tainting warnings
-T enable tainting checks
-u dump core after parsing program
-U allow unsafe operations
-v print version, patchlevel and license
-V[:variable] print configuration summary (or a single Config.pm variable)
-w enable many useful warnings
-W enable all warnings
-x[directory] ignore text before #!perl line (optionally cd to directory)
-X disable all warnings

Run 'perldoc perl' for more help with Perl.

最近处理线上问题,需要捞日志,因为日常Perl风格的正则写的比较多,所以希望能直接一条命令导出,省的多个编辑器之间来回切换。

但是目前几乎所有命令都只支持POSIX风格的正则,记录一下解决方案:

  1. grep 可以通过-P参数,但是必须要下载 gnu 的 grep 才支持,mac 本身的不支持
  2. sed不支持Perl风格,也不会支持,解决方法是换命令,perl几乎 mac 都是装机自带的。
  3. -p会打印输出,比较适合做管道处理。-e就是执行后面的命令。
1
cat 240120.json | ggrep -P "\"args\": \"mid" | perl -pe 's/\s+"args": "mid:([0-9]+)([ \S]+)/$1/'

#https://go.dev/doc/gc-guide

Until Go 1.19, GOGC was the sole parameter that could be used to modify the GC’s behavior. While it works great as a way to set a trade-off, it doesn’t take into account that available memory is finite. Consider what happens when there’s a transient spike in the live heap size: because the GC will pick a total heap size proportional to that live heap size, GOGC must be configured such for the peak live heap size, even if in the usual case a higher GOGC value provides a better trade-off.

GOGC在配置的时候没有考虑内存有限的情况,当出现有临时的内存突增时,要么 gc 阈值过高导致 oom,要么考验开发/运维,要在配置时考虑到内存激增的情况,配置对应可用的 GOGC。

为了避免参数滥用,golang 限制了 gc 时间,使得理论上的最坏情况是程序性能下降两倍。

#-1%3=?

差点因为这个表达式写了一个 bug,测试了多个语言,发现只有 python 会返回 2。
数学定义上没有对负数的取模进行精确定义,所以只依赖具体语言实现。
对于go/c/php,这个值会返回 -1