Chinaunix首页 | 论坛 | 博客
  • 博客访问: 860213
  • 博文数量: 221
  • 博客积分: 10033
  • 博客等级: 上将
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-06 22:00
文章分类

全部博文(221)

文章存档

2010年(8)

2009年(1)

2008年(69)

2007年(63)

2006年(80)

我的朋友

分类:

2008-10-29 18:47:42

Using Emacs for Perl Programming

There is a default perl-mode for Emacs. However, there is a better one hidden within Emacs. The following lisp statements will activate cperl-mode.

;; Use cperl-mode instead of the default perl-mode
(add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))

Since I do not like the default indentations, I have the followings:

(add-hook 'cperl-mode-hook 'n-cperl-mode-hook t)
(defun n-cperl-mode-hook ()
(setq cperl-indent-level 4)
(setq cperl-continued-statement-offset 0)
(setq cperl-extra-newline-before-brace t)
(set-face-background 'cperl-array-face "wheat")
(set-face-background 'cperl-hash-face "wheat")
)


Using Emacs for Perl Scripts

If you have perl installed on your computer, you may debug a perl script by simply typing "alt-x perldb" "perl -d myscript.pl". Once the command is entered, you will see 2 buffers in Emacs, the top buffer is the debugger, the bottom buffer is your perl script.



ActiveState Perl / Cygwin Bash Shell / Emacs

If you have ever tried to use ActiveState Perl in a Cygwin Bash shell, you will find that only the commands of the following formats can be run successfully.

  • perl myscript.pl
  • perl c:/workarea/myscript.pl
  • c:/perl/bin/perl myscript.pl

On the other hand, the following formats will give you a problem complaining the perl script specified cannot be found.

  • perl -S myscript.pl
  • perl /cygdrive/c/workarea/myscript.pl
  • c:/perl/bin/perl -S myscript.pl

This is because of the fact that ActiveState Perl program cannot understand Cygwin's mount drives.

There is a solution by to allow users to run ActiveState Perl in Cygwin Bash shell.

My solution is to make a C () executable that will convert the Cygwin path to Windows path before invoking the ActiveState Perl. You may have to change the path of ActiveState perl.exe in perlproxy.c according to your installation.

  • gcc -mno-cygwin perlproxy.c -o perl.exe
  • mv perl.exe /usr/local/bin/perl.exe

Now your Perl scripts should have #!/usr/local/bin/perl as the first line for things to work properly. The only side effect that I have seen so far is that you cannot type /usr/local/bin/perl in a shell to run the Perl program interactively. You will have to specify the actual path of the ActiveState Perl (for example, c:/programs/perl/bin/perl) in this case.

阅读(1140) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~