[BNE-PM] Development Tools for Perl
David Bussenschutt
d.bussenschutt at mailbox.gu.edu.au
Tue Dec 17 22:58:19 CST 2002
Give this man the one-liner award! I love it! So, does anyone else
use perl to edit perl code?
If the program edited itself, perhaps it could auto-rerun itself after the
changes too.....
I've got code in my library of snippets that checks the checksum of a
file, and I've got perl code that re-exec's itself on demand (usually
after getting a kill -HUP signal), so why couldn't we easily have a perl
program that re-exec's itself automatically whenever it determines that
the code's checksum has changed? Seems to me like a fun (if not
potentially useful) thing to do...especially for "daemon" type code and
the like where the process is always running.
;-)
David.
--------------------------------------------------------------------
David Bussenschutt Email: D.Bussenschutt at mailbox.gu.edu.au
Senior Computing Support Officer & Systems Administrator/Programmer
RedHat Certified Engineer.
Member of Systems Administrators Guild of Australia.
Location: Griffith University. Information Technology Services
Brisbane Qld. Aust. (TEN bldg. rm 1.33) Ph: (07)38757079
--------------------------------------------------------------------
Dean Povey <povey at wedgetail.com>
Sent by: owner-brisbane-pm-list at pm.org
18/12/2002 02:18 PM
To: Don.Simonetta at mincom.com
cc: brisbane-pm-list at happyfunball.pm.org
Subject: Re: [BNE-PM] Development Tools for Perl
>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