我正在阅读Think Perl 6 by Laurent Rosenfeld,与Allen B. Downey 最近这是一篇非常不错的阅读。使用Perl处理批处理文本6
它有它的.tex文件可在github here。
为了做到这一点,我们必须批处理过程包含在上述存储库中的所有.tex文件。 为了做到这一点,我们必须转换乳胶代码:
\begin{verbatim}
say 42 == 42; # True
say 42 == 42.0; # True
say 42 === 42; # True
say 42 === 42.0; # False
\end{verbatim}
\begin{verbatim}
$x eq $y # $x is string-wise equal to $y
$x ne $y # $x is string-wise not equal to $y
$x gt $y # $x is greater than $y (alphabetically after)
$x lt $y # $x is less than $y (alphabetically before)
$x ge $y # $x is greater than or equal to $y
$x le $y # $x is less than or equal to $y
$x eqv $y # $x is truly equivalent to $y
\end{verbatim}
TO
\begin{minted}{perl6}
say 42 == 42; # True
say 42 == 42.0; # True
say 42 === 42; # True
say 42 === 42.0; # False
\end{minted}
\begin{minted}{perl6}
$x eq $y # $x is string-wise equal to $y
$x ne $y # $x is string-wise not equal to $y
$x gt $y # $x is greater than $y (alphabetically after)
$x lt $y # $x is less than $y (alphabetically before)
$x ge $y # $x is greater than or equal to $y
$x le $y # $x is less than or equal to $y
$x eqv $y # $x is truly equivalent to $y
\end{minted}
我想用Perl 6 做到这一点这里是我打算做。
THIS IS DUMMY CODE
# First I want to skim all the .tex files in the cloned repo (with git)
for dir("ThinkPerl6/book") ->$file {
say $file if $file~~/\.tex/;
}
# Read each .tex file and modify, replace `\begin{verbatim}` with `\begin{minted}{perl6}`
for "$file.tex".IO.lines -> $line {
substitute with "\begin{minted}{perl6}" if $line ~~/\\begin\{verbatim\}/;
}
# Read each .tex file and modify, replace `\end{verbatim}` with `\end{minted}`
for "$file.tex".IO.lines -> $line {
substitute with "\end{minted}" if $line ~~/\\end\{verbatim\}/;
}
我不能超越那个。任何帮助?使用正则表达式会很有帮助。
最好的问候,
网速慢
基本思想(简单的文本替换,你可能甚至不需要正则表达式)是健全的。你的程序不工作?如果是这样,反而会发生什么? – Thilo
不会简单的字符串替换就足够了吗?你的可变部分在哪里? – Jan
只有第一个代码工作在目录中读取所有.tex文件。休息是我的虚拟代码,我喜欢如何继续。 –