[BNE-PM] Development Tools for Perl

Dean Povey povey at wedgetail.com
Tue Dec 17 22:18:56 CST 2002


>My tool of choice: gvim - graphical vim (improved vi).
>
>It has all the usual power of "vi" with an additional GUI front-end.
>There are many other features but the most obvious is the colouring for
>syntax recognition. It recognises a swag of languages including perl. It
>runs on both unix & win32 and the most important feature of all is its
>free! Available from http://www.vim.org

What! You don't use shell and perl one liners to edit your code?

1. Starting from scratch

$ cat <<EOF > helloworld.pl
#!/usr/bin/perl

print "This is my hello world pogram!\n";
EOF


2. Fixing a typo

$ perl -pi -e 's,pogram,program,' helloworld.pl

3. Inserting a line

$ perl -pi -e 'print "use strict;\n" if $. == 2;' helloworld.pl

4. Undo last change

$ mv helloworld.pl.bak helloworld.pl

5. Add a loop around the print statement

$ perl -pi -e 's,(^print .*;$),for my $i (0..100) {
> $1
> }
> ,' helloworld.pl


6. Indent the code
perl -pi -e '$t++ if $l =~ /{$/; $l=$_; $t-- if /}$/; print "    " x $t' \
	helloworld.pl 

7. Delete various lines (in this case the 3rd and 5th lines)

$  perl -pi -e 'undef $_ if grep /^$.$/ (3,5)' helloworld.pl

8. Create an unrolled loop of 100 items

$ perl -pi -e 'print $_ x 100 if /print/' helloworld.pl

9. Change 20 of these items

$ perl -pi -e 's,\".*\","This is not my hello world program\\n", if $. >= 10 \
	&& $. < 20' helloworld.pl

10. Display your code with line numbers

$ perl -p -e 'print "$.\t"' < helloworld.pl

11. Syntax highlight your code (Requires ANSI terminal

$  perl -p -e 's,(\#.*$),\033[32m$1\033[0m,;s,(if|elsif|unless|else|while|for|foreach|do|until|continue|goto|return|last|next|redo|in|sub|my|local|die),\033[1;31m$1\033[0m,g unless /#|\"/;s,(push|pop|grep|map),\033[1;33m$1\033[0m,;s,(\"[^\"]*\"),\033[1;32m$1\033[0m,g unless /#|\"/' < helloworld.pl

And so on.... It is the only tool you need :-).




More information about the Brisbane-pm mailing list