Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: concatenating elements of an array in twos

by tangent (Vicar)
on Aug 16, 2016 at 23:27 UTC ( #1169875=note: print w/replies, xml ) Need Help??

in reply to concatenating elements of an array in twos

Where you have
if ($sid eq $sidtwobinder[0])
you are not getting a match because $sid is "1" and $sidtwobinder[0] is "sid 1" (note the two spaces between sid and 1). You could change your @sid array to contain the whole text. I don't know how big your dataset is but it is inefficient to loop through @unpairedSidBinder inside the outer loop. You could split it into two stages, saving the matches in a hash of arrays - something like:
my @sid = ('sid 1','sid 2','sid 7','sid 9'); my %hoa; foreach my $el (@unpairedSidBinder){ my ( $key, $data ) = split /\|/,$el; push( @{ $hoa{$key} }, $data ); } foreach my $key (@sid) { my $ary = $hoa{$key} or next; my $temp = join(" ", @$ary ); print "$key|$temp\n"; }

Replies are listed 'Best First'.
Re^2: concatenating elements of an array in twos
by Sandy_Bio_Perl (Beadle) on Aug 16, 2016 at 23:50 UTC

    Thank you

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1169875]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-05-16 07:54 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (62 votes). Check out past polls.