[sf-perl] My perl idiom/"I like" of the moment

yary not.com at gmail.com
Wed May 12 10:36:33 PDT 2010

I'm converting a bunch of database scripts from one platform to
another (Teradata -> Netezza). It's a combination of edits that
require 0 thought vs some that require a little thought. At the start
of it I wrote a script "bt2nz" to automate the changes that required
the least thought, eg

  s/select \s+date,\s+time\b/select current_date, current_time/gi;

It reads input using a "while (<>)" loop and prints to stdout, so I
can pass it a script at a time and pipe it to "less" to check for

$ bt2nz report_adinfinitum.sql | less

What's making me happy is quite minor but here it is, after checking
that all is well I can replace the file contents like so
$ perl -i bt2nz report_adinfinitum.sql

and no move, rename fuss. Then I go edit the file for the bits that
require human smarts.

If I trust my script enough I can type perl -i bt2nz *.sql (and since
everything is under version control, why not)... or perl -i.bak bt2nz
*.sql to keep backups

- To be honest, it's my little script making my life easier that I'm
happy with, more than the -i option... but having a use for it outside
of a one-liner is pretty nifty too.

More information about the SanFrancisco-pm mailing list