Thread spliten von mehrdimensionalem array (21 answers)
Opened by anou at 2010-10-28 19:59

topeg
 2010-10-28 21:22
#142306 #142306
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Also hast du gar kein ArrayofArrays. Das musst du auch sagen...
da ist die Herangehensweise etwas anders:


Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;

my @array1=(
  'small_motif_b 789 799',
  'small_motif_a 811 821',
  'small_motif_i 822 832',
  'tall_motif_a 833 880',
  'small_motif_a 881 891',
  'small_motif_b 892 902',
  'small_motif_a 903 913',
  'tall_motif_b 914 961',
  'small_motif_a 962 972',
  'tall_motif_c 973 1020',
);

my @array2=(
  'NC_010109.1 NTRFinder . . . ID=NTR-a1;Parent=NTR-a;Name=motif_small_b',
  'NC_010109.1 NTRFinder . . . ID=NTR-a2;Parent=NTR-a;Name=motif_small_a',
  'NC_010109.1 NTRFinder . . . ID=NTR-a3;Parent=NTR-a;Name=motif_small_i',
  'NC_010109.1 NTRFinder . . . ID=NTR-a4;Parent=NTR-a;Name=tall_motif_a',
  'NC_010109.1 NTRFinder . . . ID=NTR-a5;Parent=NTR-a;Name=motif_small_a',
  'NC_010109.1 NTRFinder . . . ID=NTR-a6;Parent=NTR-a;Name=motif_small_b',
  'NC_010109.1 NTRFinder . . . ID=NTR-a7;Parent=NTR-a;Name=motif_small_a',
  'NC_010109.1 NTRFinder . . . ID=NTR-a8;Parent=NTR-a;Name=tall_motif_b',
  'NC_010109.1 NTRFinder . . . ID=NTR-a9;Parent=NTR-a;Name=motif_small_a',
  'NC_010109.1 NTRFinder . . . ID=NTR-a10;Parent=NTR-a;Name=tall_motif_c',
);

for my $pos (0..$#array2)
{
  my @l=split(/ /,$array2[$pos],3);
  splice(@l,2,0,$array1[$pos]);
  $array2[$pos]=join(' ',@l);
}

print Dumper(\@array2);


EDIT:
oder:
Code (perl): (dl )
1
2
3
4
5
6
#...
for my $pos (0..$#array2)
{
  $array2[$pos]=~s/^(\S+\s+\S+\s+)/$1$array1[$pos] /;
}
#...

Last edited: 2010-10-28 21:29:01 +0200 (CEST)

View full thread spliten von mehrdimensionalem array