Yes i have posted the question first on stackoverflow and they suggested me perlmonks would help you.

Could you provide a link? At the link I posted above there is no such reference to PerlMonks.

Can you please help me?

Well, first of all, it seems the code you posted doesn't work, as opposed to what was posted on StackExchange, so I'll look at the latter.

$ cat input.txt 5 5 6 11 16 7 12 $ perl -e '@j=split$",<>;print$% map$%+=2*$q[$_%@j[1]]++,split$",<>' i +nput.txt $ perl -e '@j=split$",<>;map$r+=2*$a[$_%@j[1]]++,split$",<>;print$r' i +nput.txt 8

I take it you're not allowed any switches like e.g. -F? Anyway, here's one idea:

$ perl -e '<>=~/\d+$/;map$r+=2*$a[$_%$&]++,split$",<>;print$r' input.t +xt 8

Update: That's 50 chars... what do I win? ;-) Update 2: tybalt89 shows how it's done, very nice :-)


In reply to Re^3: Golf code in perl (updated) by haukex
in thread Golf code in perl by tt08

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.