Hi. I am Fighter2. I am a seeker of Perl Wisdom.

Say, for example, I have two arrays @a and @b, and @b is 11 elements in length.

There is a certain scalar $x whose value needs to be the first element @a. If scalar $x is 4, then I need to copy @b 4 times to @a after $x is copied (hence we will be pushing @b). So array @a will have 1 + 11 *4 elements = 45. If $x is 2, then I need to copy @b 2 times to @a. $x is a variable, and can range from 0 to 6.

@b is constantly being written to @a as many $x times by a loop.

Here. This will give you a small idea

do{ my @a; push @a, $x; for(my $i=0;$i<$x;$i++){ #for each sector for(my $j=0;$j<$numFngs;$j++){ push @b, $obj->{sectors}->{$sector}->{$j}->{c2i}; } push @a, @b; } $x=update($x); }while (certain event to end);

Now, what I dont know how to make is this,.. One single record of @a should contain 49 elements at any given time. because I am reading 49 elements at a time. First element is the value from $x, and the rest is $x times of @b. But if $x is less than 6, then the rest of that 49 elements should be padded with zeros. The reason for this is, I want to be able to read the array @a from every instance of $x. If I know @a always has $x coming at every 49th element, this is easy. How do I make a loop like this to make @a?


In reply to I need some wisdom. How do I pack an array to a set length. by Fighter2

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.