Phoenix.pm: Meeting 05/03/2001

Tim Ayers tayers at bridge.com
Wed May 2 14:08:01 CDT 2001


Hello and Good Day,

This seems like a reasonable time to introduce myself. My name is Tim
Ayers and I currently live and work in Oklahoma City, Oklahoma. I'm
subscribed to the phoenix-pm list because in June, 2002 my family is
moving to Fountain Hills. I am a programmer/manager for Bridge
Information Systems, a financial information company. I have
programmed almost exclusively in Perl for the past 3.75 years and am a
Perl zealot.

>>>>> "D" == Doug Miles <doug.miles at bpxinternet.com> writes:
D> Well, so far, it will be a short discussion.  I haven't received
D> any [short utilities or one-liners] from anyone.  So start sending away

I really like one-liners and Perl Golf. If I'm not out of line, I would
like to offer a few. These are my code unless otherwise noted.

  * Strip off leading whitespace from each line of a file(s).

      perl -i -pes/^\\s+// <files>

  * Probably the coolest, least efficient way to calculate factorials 
    from Rick Klement (rklement at pacbell.net):

      sub factorial { eval join '*', 1 .. shift }

  * Given a csv file with 8 columns. Merge colums 4, 5, 6 and 7. So 
      1,2,3,4,5,6,7,8,9 => 1,2,3,4567,8,9 
    Obviously none of these examples handle embedded commas.

    A fairly comprehensible method that nicely exhibits the -F flag:

      perl -F'(,)' -ane'@F[7,9,11]=();print at F'

    To save a couple "strokes" in Perl Golf, you lose a lot of
    readability, but it contains some nice Perlisms.

      perl -pe'$i=0;s/,/1<abs++$i-5&&$&/eg'

    But the most elegant (and shortest) solution is from 
    Tim Gim Yee (tgy at chocobo.org), who "thought outside the box" by
    not treating each line as a line, but looked at the file
    record-by-record.

      perl -054pe'abs$.%8-5<2&&chop'

    (To confirm your suspicions 054 == 44 == ord(',').)

Anyway, HTH and 
Hope you have a very nice day, :-)
Tim Ayers (tayers at bridge.com)




More information about the Phoenix-pm mailing list