Режим Emacs org: как создавать грамотные программы с синтаксисом noweb
Я пытаюсь создать эту программу 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);
Я создал этот файл org:
#+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;
}
Проблемы:
- В верхней части файла есть пустая строка.
- Блок Новеб не был расширен, но помещен в конец файла.
- Я не понимаю, как написать имя выходного файла один раз в верхней части? В настоящее время я должен переписать его для каждого блока:
:tangle test.pl
,
1 ответ
Решение
Вот решение:
#+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
- Класть
#!/usr/bin/perl
к верхней строчке:shebang #!/usr/bin/perl
- Имена блоков Noweb не должны содержать пробелов. Замените их на "-".
- Напишите имя файла для корневого блока noweb.