Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: concatenating elements of an array in twos

by tangent (Parson)
on Aug 16, 2016 at 23:27 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 12:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found