See Also: Home Links Personal Site Blogroll  FriendFeed CV

Tags:

Topic Image

OSDC : Perl White Magic

This was a presentation at OSDC 2006 in Melbourne presented by José Castro (aka Cog), a portugese Perl developer and CPAN contributor. The talk was on command line switches used to run one-liners directly instead saving them as seperate multi-line but relatively simple perl scripts.

This is all very well if you can remember the purpose of the switches, and I went into the talk a bit sceptical thinking I thought I new what the obviously useful switches were and that the rest were just esoteric weirdities. Turns out I was wrong and the following were shown to be bloody handy...

  • -e : evals a bunch of code provided in a quoted string (this one I knew about, it was combining it with the following which was an eye-opener to me)
  • -n : wraps an implicit while loop around any '-e' (eval) provided code to iterate over the values piped into perl
  • -i : specifies that files processed by the <> construct are to be edited in-place
  • -l : enables automatic line-ending processing
  • $. : tracks the currenly STDIN line number (so you dont have to)
  • $, : overides the default output field separator for the print operator
  • @F - array containing auto-split fields of current input line

José has published the Presentation Slides which is worth reading coz these switches only really come to light when you see examples of them in action. There are so many other vars too, check out Perlvar and Perlrun for details if your feeling brave.


See Also: OSDC 2006 | Web Development | Notes Index