Damian Conway on Regexes

Watched this talk on Regular Expressions by Damian Conway today. He discusses how RE engine is actually a virtual machine and how regular expressions are source code that is executed inside the VM. He goes on to discuss NFA and DFA engines and show how regular expressions work and gives some tips for using them.

 

  • RE engine is a VM, executing code (the regular expression)
  • Lack of whitespace in REs is a real problem.
    • In addition to perl’s /x switch to enable extended formatting (which I know of but don’t use as much as I should), comments and whitespace can be added to PCREs by starting them with (?x)
  • Editor REs typically require metacharacters to be escaped with backslashes – eg /a|b/ becomes /a\|b/ in emacs
  • To improve performance try to reduce backtracking, think about whether to use maximal or minimal loops and try to write REs that will succeed rather than fail
Standard

Various ssh tricks

I spend the majority of my workday using ssh and yet only use a few of its features. I do use multiplexed sessions nowadays (ControlMaster / ControlPath in ~/.ssh/config), I love editing over ssh with emacs tramp mode (open file /<hostname>:<path>) and I’m fairly used to simple port forwarding, but there some fancy things like mounting filesystems over ssh and using it as tunneling proxy explained here that are worth looking at.

Standard

Recovering an orphaned process and some fun with gdb

Back when I was just starting with unix as a student I remember losing connection to the university’s mailserver in the middle of composing a long email. I went over to the helpdesk and asked if I could recover the process in a new login session, I got a few blank looks and not much else. It seems that it’s still not easy.

We were discussing this a few months ago and I came across this¬†post by Andrew Tridgell (of samba fame) shows how this can be done with gdb (as well as some other gdb hacks, turns out there’s all kinds of interesting stuff if you actually read the manual. Who would have thought it!).

We also discovered reptyr, a project that does the same thing using ptrace. I’ve not actually used it but it looks interesting.

Standard

Perl talk: more awesome things you have missed in perl

Watched this video last week, a number of neat things to look in to

  • Moose – A decent looking implementation of OO perl. Check out also some of the MooseX modules, like signatures, Moose::Util::TypeConstraints and probably a lot more.
  • Autobox – Automatically build oo interfaces to lots of perl builtins. Also see Moose::Autobox
  • autodie – Already knew about this, but there’s a lot more to it than I was aware of. Check the docs
  • Try::Tiny – Nice exception handling
  • cpanm / local::lib / ¬†metacpan.org – Improved installing of modules, local module install dirs and an improved interface to cpan
  • Named regexp captures – No need to worry that capture numbering might change when editing code
  • Grammars / Regexp::Grammar – Grammatical parsing
  • Dancer – Nice web framework
  • PAR, App::FatPacker – Package perl and dependencies into one blob
  • Devel::NYTProf – Very nice looking profiler
  • Perl::Critic – Feedback on perl coding style. Also includes user contributed summaries if you don’t have Perl Best Practices handy (increase verbosity!)

Also the usual stuff I don’t use (use 5.10.0 / 5.12.0 , say, given / when and maybe perl5i)

Standard