Update: LanX had the module (List::MoreUtils) that I was trying to find. Nothing to see here. Move along.

I am not certain that this is what you are looking for, but I seem to remember seeing code to fold arrays together in various ways. Below you will find an example of a simple folding subroutine. This could be made generic enough to be able to handle any number of arrays.

use strict; use warnings; use Data::Dumper; $Data::Dumper::Sortkeys = 1; $Data::Dumper::Indent = 0; sub array_fold { my $a1 = shift; my @a1 = @$a1; my $a2 = shift; my @a2 = @$a2; my $folder = shift || sub { [ @_ ] }; die "Arrays are not of the same size" unless scalar( @a1 ) == scalar( @a2 ); my @results; while( scalar( @a1 ) && scalar( @a2 ) ) { push @results, $folder->( shift( @a1), shift( @a2 ) ); } return @results; } my @a = qw( a b c d ); my @b = qw( A B C D ); my @results = array_fold( \@a, \@b ); print Dumper( { results => \@results } ), "\n"; my @results2 = array_fold( \@a, \@b, sub { "@_" } ); print Dumper( { results2 => \@results2 } ), "\n"; __END__ $VAR1 = {'results' => [['a','A'],['b','B'],['c','C'],['d','D']]}; $VAR1 = {'results2' => ['a A','b B','c C','d D']};

--MidLifeXis


In reply to Re: Concatenating more than one variable in perl by MidLifeXis
in thread Concatenating more than one variable in perl by manoj_speed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.