|
Guest
Posts: n/a
|
On May 6, 9:49 am, Tad McClellan <t...@augustmail.com> wrote:
> Tradeorganizer <tradeorgani...@gmail.com> wrote:
> > values in x and y are :
>
> > $x[0] = (1,2,3,4)
>
> Please speak Perl rather than English, when possible.
>
> $x[0] = [1,2,3,4];
>
> > $x[1] = (2,3,4,5)
> > ....
> > till
> > $x[31] = (1,1,1,1)
>
> Wouldn't having just 2 or 3 illustrate your problem just as
> well as having 32 of them?
>
>
>
> > now the value of y contains
>
> > $y[0] = (2,2,3,4)
> > $y[1] = (2,3,3,5)
> > ....
> > till
> > $y[31] =(4,4,4,4)
> > .....
>
> > till
> > $y[500] = (1,1,1,1)
>
> > i want to make a loop where i can append the array y or create new
> > array with having array x value fixed till record [31] ie end of array
> > x plus value of array[y] till record [31] and then repeating again the
> > value of array x to next records of array y i mean till next 31
> > records of y
>
> If I understand you correctly, then I think this does it:
>
> ----------------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
> use Data: umper;
>
> my @x = (
> [1,2,3,4],
> [2,3,4,5],
> );
>
> my @y = (
> [2,2,3,4],
> [2,3,3,5],
> [3,4,5,6],
> [7,8,9,0],
> [1,1,1,1],
> );
>
> my @newxy;
> for ( my $xi = my $yi = 0; defined $y[$yi]; $xi++, $yi++ ) {
> push @newxy, [ @{ $x[$xi] }, @{ $y[$yi] } ];
> $xi = -1 if $xi == $#x; # roll back to zero
>
> }
>
> print Dumper \@newxy;
> ----------------------------
>
> > kindly help i know perl
>
> Then you should be able to speak Perl in your posts.
>
> Have you seen the Posting Guidelines that are posted here frequently?
>
> --
> Tad McClellan SGML consulting
> t...@augustmail.com Perl programming
> Fort Worth, Texas
Hi Tad ,
Thanks for your reply , it worked , but the output i am getting is
below :
C:\perlprog>testlooprt.pl
$VAR1 = [
[
1,
2,
3,
4,
2,
2,
3,
4
],
[
2,
3,
4,
5,
2,
3,
3,
5
],
[
1,
2,
3,
4,
3,
4,
5,
6
],
[
2,
3,
4,
5,
7,
8,
9,
0
],
[
1,
2,
3,
4,
1,
1,
1,
1
]
];
where as i need like
$VAR1 = [ [ 1, 2, 3, 4, 2, 2, 3, 4 ],
how can i do that.
Regards
|
|