Here's a simple way:
Here's an alternative way using the List::MoreUtils CPAN module:my @nums = (1, 2, 4, 5, 8, 9); my @dat = (3, 9, 14, 10, 12, 8); for my $i ( 0 .. $#nums ) { print "$nums[$i] $dat[$i]\n"; }
Update: Simpler solution using the pairwise function:use List::MoreUtils qw(zip natatime); my @nums = (1, 2, 4, 5, 8, 9); my @dat = (3, 9, 14, 10, 12, 8); my $it = natatime( 2, zip(@nums, @dat) ); while ( my @vals = $it->() ) { print "@vals\n"; }
use List::MoreUtils qw(pairwise); my @nums = (1, 2, 4, 5, 8, 9); my @dat = (3, 9, 14, 10, 12, 8); print pairwise { "$a $b\n" } @nums, @dat;
In reply to Re: how to print two array with new line at end of each second array element, using a single print statement?
by eyepopslikeamosquito
in thread how to print two array with new line at end of each second array element, using a single print statement?
by gourish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |