Emacs, Perl

Emacs: align perl hash with align-current

I often write Perl script and use hash heavily. But I feel boring (and a little bit stupid) to align “=>” manually. For example, press SPACE to align

my %h =
    (
        key1 => value1,
        key11 => value11,
        key111 => value111,
    );

to

my %h =
    (
        key1   => value1,
        key11  => value11,
        key111 => value111,
    );

After reading Ruslan’s align-regexp, I find align-current and bind it to C-c C-c in cperl-mode.

(define-key cperl-mode-map "\C-c\C-c" 'align-current)

So, I can align those lines of Perl code simply by moving cursor to one of three lines and pressing C-c C-c.

Standard
Cygwin, Parrot

Parrot: build parrot on cygwin

Building parrot on cygwin is not as straightforward as on other platforms. You have to add path of libparrot.dll into PATH environment variable. For example,

PATH=/path/to/parrot/blib/lib:$PATH

It’s better to add this line into your .bashrc file so that you do not need to run it every time you start a console.

After that, you can follow basic building steps to build parrot.

$ perl Configure.PL
$ make

To test parrot, write a hello.pir

.sub main
    print "Hello world!\n"
.end

And then run it

$ parrot hello.pir

If everything is ok, you should get a string as output.

Standard
Makefile

Makefile: whitespace in path

I hates whitespace in path. I wrote a Perl script which uses a resource file and several template files. So I created a makefile to copy them to user’s HOME directory. It looks like:

$(HOME)/a: a
      cp -f $< $@

Unfortunately, it doesn’t work when there are whitespaces in $(HOME) string, such as /abc/d e/. That happens on Cygwin default installation.

You can double-qoute path, but there are whitespaces in target and target can not be double-qouted. Finally, I find a workaround after diving into `make' info page for a long time. Here is the trick.

nullstring :=
space := $(nullstring) # a space at the end
QUOTED_HOME=$(subst $(space),\ ,$(HOME))
$(QUOTED_HOME)/a:a
      cp -f $< $(subst $(space),\ ,$@)

Standard