Rather that trying to shoehorn pack into a solution, it seems simpler to me to regex it (caution: needs Perl version 5.10+ for  \K operator):

c:\@Work\Perl\monks\kanikas16>perl -wMstrict -le "use 5.010; ;; my $s = '(1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 ' . '2 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 ' . '3 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 ' . '10 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 ' . '11 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 ' . '987 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0)' ; print qq{<<$s>> \n}; ;; my $bar = qq{\n} . 'x' x 35 . qq{\n}; $s =~ s{ \A \( \K }{\n}xms; $s =~ s{ \d+ \s+ (?: [01] \s+){17} \K }{$bar}xmsg; print qq{<<$s>>}; " <<(1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 2 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 + 0 1 3 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 10 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 11 + 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 987 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0)>> <<( 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 3 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 10 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 11 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 987 1 1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0)>>
This is based on the updated version of kanikas16's OP and (almost!) exactly produces the desired output. The only thing I can't get simply via substitutions is the use of a 36-'x' separator after row 8 (per the OP) rather than the 35-'x' separator used everywhere else. I'm assuming (and hoping!) this is just a typo; it would be possible to accommodate something like this with a substitution, but messy! (Note: This solution needs Perl 5.10+ for the  \K operator, but a non-\K solution is fairly painless; let me know if it's needed.)


Give a man a fish:  <%-{-{-{-<


In reply to Re: Count and print in perl by AnomalousMonk
in thread Count and print in perl by kanikas16

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.