Heres a one liner:
perl -ne "@_=split/,/;$a=@_>2?@_-3:0;print join',',@_[$a..$#_]"
You can pipe into this or pass it a list of filenames that it should convert. It'll print it all to STDOUT.

I personally think that this is homework. I offer my solution anyway. :-)

The reason I think its homework is because its one of those simple questions thats easy to get wrong. All of the monks that offered code so far, (fwict) to their collective shame no doubt ;-), have actually not provided working code. And they seem to have some knowledge. No doubt a little more testing, a live sample of the data, whatever and they quickly would have noticed the oversight and fixed it correctly. But the fact remains. :-)

Anyway, don't think I was any better, I didn't notice the mistake until I did jdporters as a one liner and played with it for a few lines. I'm betting everybody who replied (and maybe a few more, since this'll be at the bottom of the list) are right about now smacking their foreheads and saying "less than three values" :-) (update the grep solution is only backwards...) Cause thats what I did.

Cheers.

PS: on *nix I think you spell it

perl -ne '@_=split/,/;$a=@_>2?@_-3:0;print join",",@_[$a..$#_]'
but i'm not sure.

UPDATE If anybody wants to see the results of what has been posted so far read the source of this node.

--- demerphq
my friends call me, usually because I'm late....


In reply to Re: counting number of fileds by demerphq
in thread counting number of fileds by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.