#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $line = <DATA>; #get started with first line chomp $line; my ($prev_sidpart,$prev_rest) = split /\|/, $line; while (my $line = <DATA>) { chomp $line; my ($cur_sidpart,$cur_rest) = split /\|/, $line; if ($prev_sidpart eq $cur_sidpart) { $prev_rest .= " $cur_rest"; } else { print "$prev_sidpart|$prev_rest\n"; ($prev_sidpart,$prev_rest) = ($cur_sidpart,$cur_rest); } } print "$prev_sidpart|$prev_rest\n"; #last record =prints: sid 1|FLPSDFFPS LLWFHISCL WIRTPPAYR YVNVNMGLK sid 2|FLPSDFFPS LLWFHISCL FLPSDFFPS ELMNLATWV sid 7|FLPSDFFPS ATVELLSFL VWIRTPPAY LLSFLPSDF sid 9|VWIRTPPAY LLDTASALY FGRETVLEY PSDFFPSVR =cut __DATA__ sid 1|FLPSDFFPS LLWFHISCL sid 1|WIRTPPAYR YVNVNMGLK sid 2|FLPSDFFPS LLWFHISCL sid 2|FLPSDFFPS ELMNLATWV sid 7|FLPSDFFPS ATVELLSFL sid 7|VWIRTPPAY LLSFLPSDF sid 9|VWIRTPPAY LLDTASALY sid 9|FGRETVLEY PSDFFPSVR
In reply to Re: concatenating elements of an array in twos
by Marshall
in thread concatenating elements of an array in twos
by Sandy_Bio_Perl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |