1 2 3 4 5 6 7 8 9 10 11 12 13
my @array = qw( liste mit 1000 elementen ); my @new; # combine every first and second element with a whitespace while ( @array ) { push @new, join( " " , splice( @array, 0, 2 ) ); } # check for ( @new ) { print "$_", $/; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#! /usr/bin/perl use strict; use warnings; use Data::Dumper; my @list = qw( Liste mit 1000 Elementen und eins mehr); my $separator = ''; # empty string my @new; while ( my @join_these = splice( @list, 0, 2 ) ) { no warnings 'uninitialized'; push @new, join( $separator, @join_these ); } print Dumper \@new; __END__
push @b, $a[$_*2].$a[$_*2+1] for (0..$#a/2);