cool has asked for the wisdom of the Perl Monks concerning the following question:
Problem:: I want values that I am pushing in the end with each input line (6,7....) to fetch as a loop ie it would be somewhat like given below as'desired output'. Now, I am not able to find the way so that I can get them easily. This output I am going to use for GD.pm.
Code summary- Input lines : 3-8 Subroutine : 22-68 {playing with data 33-60}# So these can be left for this + problem Printing line nos : 64 and 18
From line no 61-65 I am pushing my data into last position of each input line(line no 6,7 and 8). These pushed values in a set of 4, can be any no of times in the last place of each input line.
Pardon me if its very silly to put here. Further, pl feel free (Don't go all PerlMonks on me) to go all perl monk on me. Pl read roboticus 's second reply from Extra iteration while fetching 'fetchrow_array' in DBI and standerd way of using DBI.(I couldn't figure out how to give link to a particular reply)
My code:Desired output G6081 yaaX 5234 5530 + 6 6 244 480 540 480 EG10011 yaaA 5683 6459 - 6 7 693 480 1010 480 10 560 469 560 EG11555 yaaJ 6529 7959 - 7 8 539 560 1010 560 10 640 969 640
1 #! /usr/bin/perl -w 2 use strict; 3 my $base_length=1000; 4 my $margin=10; 5 my @midfield; 6 $midfield[0]='G6081 yaaX 5234 5530 + 6 6'; 7 $midfield[1]='EG10011 yaaA 5683 6459 - 6 7'; 8 $midfield[2]='EG11555 yaaJ 6529 7959 - 7 8'; 9 my $mid_r=\@midfield; 10 11 my $cordinate_r=genedraw($mid_r,$base_length,$margin); 12 #print "$cordinate_r->[7][0]\n"; 13 my @refer=@{$cordinate_r}; 14 #my @tempref=@{$cordinate_r->[7]}; 15 #my @tempref; 16 foreach (@refer){ 17 18 print "@{$refer[7]}\n",'&&&&&&&&&&&&&&&&&&&&',"\n"; ## + PRINT-2 19 # push (@tempref,@{$refer[7]}) 20 21 } 22 sub genedraw 23 { 24 my $arr=shift; 25 my $Blength=shift; 26 my $margin=shift; 27 my @finalarr; 28 my @field=@{$arr}; 29 foreach (@field) 30 { 31 my $X2; 32 my $Y2; 33 my @tmp=split(/\s+/);#### LINE A 34 my @temparray; 35 my$X1=($tmp[2]-(($tmp[5]-1)*$Blength))+$margin +; 36 my$Y1=80*$tmp[5]; 37 my$check=1; 38 if($tmp[5] !=$tmp[6]) 39 { 40 my$genestretchlines=$tmp[6]-$tmp[5]; 41 for my $x(1..$genestretchlines) 42 { 43 if($check==1) 44 { 45 $X2=$margin+$Blength; 46 $Y2=80*$tmp[5]; 47 $check=2; 48 } 49 push @temparray, ($X1,$Y1,$X2, +$Y2); 50 if($x!=$genestretchlines) 51 { 52 $X2=$margin+$Blength; 53 $Y2=80*($tmp[5]+$x); 54 } 55 $X1=$margin; 56 $Y1=80*($tmp[5]+$x); 57 } 58 } 59 $X2=($tmp[3]-(($tmp[6]-1)*$Blength))+$margin; 60 $Y2=80*$tmp[6]; ##### LINE B 61 push @temparray, ($X1,$Y1,$X2,$Y2); 62 my$temp_r=\@temparray; 63 $tmp[7]=$temp_r; 64 print "\n@{$tmp[7]}:::TEMP\n"; ## PRINT-1 65 push @finalarr,@tmp; 66 } 67 return (\@finalarr); 68 }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: fetching array of array, using a loop
by shmem (Chancellor) on Jun 26, 2007 at 23:05 UTC | |
by cool (Scribe) on Jun 27, 2007 at 09:04 UTC | |
by shmem (Chancellor) on Jun 27, 2007 at 10:02 UTC | |
by cool (Scribe) on Jun 27, 2007 at 11:41 UTC |