Perl array formatting

I have spent a lot of time and can not get this to work seems very simple yet I can not find the answer on my own.

I have 2 arrays that are populated by a perl module.  One contains names of countries the other contains a country code. Here is my code

#!/usr/bin/env perl

use strict;
use warnings;

use Locale::Country;

my @names = all_country_names();
my @codes = all_country_codes(LOCALE_CODE_ALPHA_2);

use Data::Dumper qw(Dumper);
print Dumper \@codes;

Open in new window

the output of @codes looks like this same for @names

$VAR1 = [

$VAR1 = [
          'Aland Islands',

Open in new window

What I want to be able to do is merge these 2 together so it looks like

$VAR1 = [ 'ad', 'AFGHANISTAN' ]
$VAR2 = [ 'ae', 'Aland Islands ]

Open in new window

tried push but that just appends them.  My goal is to be able to import them

$schema->populate('Table_name', [
  [ 'code', 'name' ],

Open in new window

Who is Participating?
ozoConnect With a Mentor Commented:
How did you try push?
If you don't need to preserve @names, you could do something like
  push @mergedarray,[$_,shift @names]for @codes;
If you don't need to preserve either, you might  do something like
  push @mergedarray,[shift @codes,shift @names]while @codes;
If you need to preserve both you might do
  push @mergedarray,[$codes[$_],$names[$_]] for 0..$#codes;  
my %merge;
my @codes = all_country_codes(LOCALE_CODE_ALPHA_2);
my  @mergedarray=map[$_,$merge{$_}],@codes;
hexfusionAuthor Commented:
push @mergedarray,[shift @codes,shift @names]while @codes; 

Open in new window

yes perfect thank you soo very much.
hexfusionAuthor Commented:
Thanks again that was great
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.