它的脚本来跟踪身份。在“离开”行中,缩进缩小,在“进入”时增加。然后我们看到空格是基于缩进变量打印的。详细介绍:
/usr/bin/perl -ne
-n
标志把周围的脚本,基本上令Perl从标准输入或从参数文件中读取一个while(<>)
循环。
BEGIN { $|=1 }
Autoflush已打开。
if (/(bmake|create_dirs\.sh)\[\d+\] Leaving/) { --$indent };
此正则表达式这里查找系如
bmake[9] Leaving
create_dirs.sh[2] Leaving
当找到,$indent
变量由1
print " "x($indent * 4), "$_" ;
这将打印的空间减小,重复4 * $indent
倍,然后是输入行。
if (/(bmake|create_dirs\.sh)\[\d+\] Entering/) { ++$indent }
该行通过与上述相同的方法增加缩进。对正则表达式(见它here,虽然我清理从该网站的语法)
更多的解释:
NODE EXPLANATION
--------------------------------------------------------------------------------
( group and capture to $1:
--------------------------------------------------------------------------------
bmake literal string 'bmake'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
create_dirs\.sh literal string 'create_dirs.sh'
--------------------------------------------------------------------------------
) end of $1
--------------------------------------------------------------------------------
\[ literal string '['
--------------------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
--------------------------------------------------------------------------------
\] Leaving literal string '] Leaving'
来源
2013-02-20 12:53:08
TLP
ü感谢这么多的TLP :) :)非常好的解释 – user2091202 2013-02-20 13:17:51
@ user2091202不客气。 – TLP 2013-02-20 13:18:33
但我想澄清的一件事是您如何编写bmake [9]和create_dirs.sh [2]。 – user2091202 2013-02-20 13:19:22