Fighter2 has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: I need some wisdom. How do I pack an array to a set length.
by ikegami (Patriarch) on Nov 23, 2011 at 20:27 UTC | |
Re: I need some wisdom. How do I pack an array to a set length.
by mr.nick (Chaplain) on Nov 23, 2011 at 20:28 UTC | |
by Tux (Canon) on Nov 24, 2011 at 07:39 UTC | |
Re: I need some wisdom. How do I pack an array to a set length.
by jwkrahn (Abbot) on Nov 23, 2011 at 21:59 UTC | |
Re: I need some wisdom. How do I pack an array to a set length.
by Marshall (Canon) on Nov 24, 2011 at 06:55 UTC | |
Re: I need some wisdom. How do I pack an array to a set length.
by TJPride (Pilgrim) on Nov 24, 2011 at 09:01 UTC |