[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] joining columns in csv files



So far we have the following solutions.

From: fergal daly <fergal@esatclear.ie>
  perl -pe'$i=1;s/,/$i++=~m#^4|5|6$#?"":","/ge'     45 chars

Yanick and Larry Rosler had several nice solutions, but they only work
for files of 1 line since they don't reset their $i counter. Fixing
that glitch gives us

From: yanick1@sympatico.ca
  perl -pe'$i=0;s/,/$&if++$i,!grep$i==$_,4,5,6/eg'  48 chars
  perl -pe'$i=0;s/,/$&if 4>++$i||$i>6/eg'           39 chars
  perl -pe'$i=0;s/,/$&if 1<abs++$i-5/eg'            38 chars

From: "Larry Rosler" <lr@hpl.hp.com>
  perl -pe'$i=0;s/,/++$i!~m%^[456]$%&&$&/ge'        42 chars
  perl -pe'$i=0;s/,/3<++$i&&$i<7?"":$&/eg'          40 chars

I shortened Yanick's best by one stroke as
  perl -pe'$i=0;s/,/1<abs++$i-5&&$&/eg'             37 chars

Personally I took a different tack, but it's only good for a tie with
4th place.  I present it in hopes that it will spawn other
solutions.
  perl -F'(,)' -ane'@F[7,9,11]=();print@F'          40 chars

Hope you have a very nice day, :-)
Tim Ayers (tayers@bridge.com)
Norman, Oklahoma where I'm expecting Ilmari to improve my solution since
I often follow his same strategy but overlook an obvious
optimization. :-}



==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe