use Data::Dump::Streamer; ... my $cordinate_r = genedraw ($mid_r,$base_length,$margin); Dump ($cordinate_r);
The question about the array at the 7th index was about wether it is required to have its elements in packs of four on different lines, or can those just be lumped together on one line?
Can't use string ("G6081") as an ARRAY ref while "strict refs" in use at perly.pl line 24.
Is that the line after the foreach loop control statement, dereferencing $ref? Seems like you are not constructing the references properly, since the incriminated token is what should be $ref->[0] inside the foreach loop, not $cordinate_r->[0]. Anyways, here is your running script, slightly reformatted to make it readable.
#! /usr/bin/perl -w use Data::Dump::Streamer; use strict; my $base_length = 1000; my $margin = 10; my @midfield; $midfield[0] = 'G6081 yaaX 5234 5530 + 6 6'; $midfield[1] = 'EG10011 yaaA 5683 6459 - 6 7'; $midfield[2] = 'EG11555 yaaJ 6529 7959 - 7 8'; my $mid_r = \@midfield; my $cordinate_r = genedraw($mid_r,$base_length,$margin); Dump ($cordinate_r); foreach my $ref(@$cordinate_r) { my $line = join ' ', @$ref[0..6]; # splice field 7 into groups of four my @ary = @{$ref->[7]}; my @coord; while(@ary) { push @coord, join ' ', splice @ary, 0, 4 ; } no warnings 'uninitialized'; write; format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<< $line, shift @coord ~@<<<<<<<<<<<<<<<<<<<<<<<< shift @coord . } sub genedraw { my ($arr, $Blength, $margin) = @_; my @finalarr; my @field = @{$arr}; foreach (@field) { my ($X2,$Y2); my @temparray; my @tmp = split(/\s+/); #### LINE A my $X1 = ($tmp[2] - (($tmp[5] - 1) * $Blength)) + $ +margin; my $Y1 = 80 * $tmp[5]; my $check = 1; if ($tmp[5] != $tmp[6]) { my $genestretchlines=$tmp[6]-$tmp[5]; for my $x (1 .. $genestretchlines) { if ($check == 1) { $X2 = $margin+$Blength; $Y2 = 80 * $tmp[5]; $check = 2; } push @temparray, ($X1,$Y1,$X2,$Y2); if ($x != $genestretchlines) { $X2 = $margin + $Blength; $Y2 = 80 * ($tmp[5] + $x); } $X1 = $margin; $Y1 = 80 * ($tmp[5] + $x); } } $X2 = ($tmp[3] - (($tmp[6] - 1) * $Blength)) + $margin +; $Y2 = 80 * $tmp[6]; ##### LINE B push @temparray, ($X1,$Y1,$X2,$Y2); $tmp[7] = \@temparray; # print "\n@{$tmp[7]}:::TEMP\n"; ## PRINT-1 push @finalarr, [@tmp]; } return (\@finalarr); }
Output:
$ARRAY1 = [ [ 'G6081', 'yaaX', 5234, 5530, '+', ( 6 ) x 2, [ 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 ] ] ]; 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
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
In reply to Re^3: fetching array of array, using a loop
by shmem
in thread fetching array of array, using a loop
by cool
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |