我正在尝试创建这个 Perl 程序:
#!/usr/bin/perl
use strict;
use warnings;
open(my $fh, "<", "test.txt")
or die "cannot open < file name: $!";
while (my $line = <$fh>) {
print $line;
}
close($fh);
我创建了这个组织文件:
#+BABEL: :cache yes :tangle yes :noweb yes
#+NAME: top_block
#+begin_src perl :tangle test.pl
#!/usr/bin/perl
use strict;
use warnings;
open(my $fh, "<", "test.txt")
or die "cannot open < file name: $!";
<<output all the lines from file>>
close($fh);
#+end_src
#+NAME: output all the lines from file
#+begin_src perl :tangle test.pl
while (my $line = <$fh>) {
print $line;
}
#+end_src
但它创造了这个:
empty line here
#!/usr/bin/perl
use strict;
use warnings;
open(my $fh, "<", "test.txt")
or die "cannot open < file name: $!";
<<output all the lines from file>>
close($fh);
while (my $line = <$fh>) {
print $line;
}
问题:
- 文件顶部有一个空行。
- Noweb 块没有展开,而是放在文件的底部。
- 我不明白,如何在顶部写一次输出文件名?目前,我必须为每个块重写它:
:tangle test.pl
.