首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Emacs模式:如何创建具有noweb语法的读写程序

Emacs模式:如何创建具有noweb语法的读写程序
EN

Stack Overflow用户
提问于 2014-10-21 18:01:18
回答 1查看 1.2K关注 0票数 4

我正在尝试创建这个Perl程序:

代码语言:javascript
复制
#!/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);

我创建了这个组织文件:

代码语言:javascript
复制
#+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

但它创造了:

代码语言:javascript
复制
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;
}

问题:

  1. 在文件的顶部有一个空行。
  2. Noweb块没有展开,而是放在文件的底部。
  3. 我不明白,怎么把输出文件的名字写在最上面一次?目前,我必须为每个块重写它::tangle test.pl
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-22 08:20:26

以下是解决办法:

代码语言:javascript
复制
#+BABEL: :cache yes :tangle yes :noweb yes

#+NAME: top_block
#+begin_src perl :tangle "test.pl" :noweb tangle :shebang #!/usr/bin/perl
  use strict;
  use warnings;

  open(my $fh, "<", "test.txt")
      or die "cannot open < file name: $!";
  <<output-all>>
  close($fh);
#+end_src

#+NAME: output-all
#+begin_src perl
  while (my $line = <$fh>) {
      print $line;
  }
#+end_src
  1. 要将#!/usr/bin/perl放到最上面的一行,请使用:shebang #!/usr/bin/perl
  2. Noweb块名称不应该包含空格。用"-“代替。
  3. 为根noweb块编写文件名。
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26493227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档