Reputation: 651
I have this part of code to catch the greater value of an array immersed in a Hash. When Perl identified the biggest value the array is removed by @slice array:
if ( max(map $_->[1], @$val)){
my @slice = (@$val[1]);
my @ignored = @slice;
delete(@$val[1]);
print "$key\t @ignored\n";
warn Dumper \@slice;
}
Data:Dumper out:
$VAR1 = [
[
'3420',
'3446',
'13',
'39',
55
]
];
I want to print those information separated by tabs (\t) in one line like this list:
miRNA127 dvex589433 - 131 154
miRNA154 dvex546562 + 232 259
miRNA154 dvex573491 + 297 324
miRNA154 dvex648254 + 147 172
miRNA154 dvex648254 + 287 272
miRNA32 dvex320240 - 61 83
miRNA32 dvex623745 - 141 163
miRNA79 dvex219016 + ARRAY(0x100840378)
But in the last line always obtain this result.
How could I generate this output?:
miRNA127 dvex589433 - 131 154
miRNA154 dvex546562 + 232 259
miRNA154 dvex573491 + 297 324
miRNA154 dvex648254 + 147 172
miRNA154 dvex648254 + 287 272
miRNA32 dvex320240 - 61 83
miRNA32 dvex623745 - 141 163
miRNA79 dvex219016 + 3420 3446
Additional explication: In this case, I want to catch the highest value in $VAR->[1] and looking if the subtraction with the minimum in $VAR->[0] is <= to 55. If not, i need to eliminate this AoA (the highest value) and fill a @ignored array with it. Next, i want to print some values of @ignored, like a list. Next, with the resultants AoA, I want to iterate the last flow...
Upvotes: 1
Views: 513
Reputation: 6204
print "$key\t $ignored[0]->[0]\t$ignored[0]->[1]";
You have an array of arrays, so each element of @ignored
is an array. The notation $ignored[0]
gets to the zeroth element (which is an array), and ->[0]
and ->[1]
retrieves the zeroth and first elements of that array.
For example:
use strict;
use warnings;
use Data::Dumper;
my @ignored;
$ignored[0] = [ '3420', '3446', '13', '39', 55 ];
my $key = 'miRNA79 dvex219016 +';
print Dumper \@ignored;
print "\n";
print "$key\t$ignored[0]->[0]\t$ignored[0]->[1]";
Output:
$VAR1 = [
[
'3420',
'3446',
'13',
'39',
55
]
];
miRNA79 dvex219016 + 3420 3446
Another option that generates the same output is to join
all the values with a \t
:
print join "\t", $key, @{ $ignored[0] }[ 0, 1 ];
Upvotes: 2