Values From Multiple Arrays

B

blnukem

Hi All

I'm REALLY lost on getting this to work maybe someone can help me I have
three arrays that look like this:

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

and I want to output this format:

john car red
bill house blue
peter motorcycle green
james house teal

Thank to all in advance
Blnukem
 
G

Gunnar Hjalmarsson

blnukem said:
I'm REALLY lost on getting this to work maybe someone can help me

What have you tried??
I have three arrays that look like this:

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

and I want to output this format:

john car red
bill house blue
peter motorcycle green
james house teal

while (@Array1) {
print (shift @Array1, ' ');
print (shift @Array2, ' ');
print (shift @Array3, "\n");
}
 
A

Anno Siegel

blnukem said:
Hi All

I'm REALLY lost on getting this to work maybe someone can help me I have
three arrays that look like this:

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

and I want to output this format:

john car red
bill house blue
peter motorcycle green
james house teal

Ah, ye olde transposition problem.

print join( ' ', map shift @$_, \ ( @Array1, @Array2, @Array3)), "\n" while @Array1;

This destroys the original arrays.

Anno
 
A

Anno Siegel

blnukem said:
Hi All

I'm REALLY lost on getting this to work maybe someone can help me I have
three arrays that look like this:

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

and I want to output this format:

john car red
bill house blue
peter motorcycle green
james house teal

Ah, ye olde transposition problem.

print join( ' ', map shift @$_, \ ( @Array1, @Array2, @Array3)),
"\n" while @Array1;

This destroys the original arrays.

Anno
 
J

Jürgen Exner

blnukem said:
I'm REALLY lost on getting this to work maybe someone can help me I
have three arrays that look like this:

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

and I want to output this format:

john car red
bill house blue
peter motorcycle green
james house teal

What's the problem? Assuming the arrays have the same length:
for (0..$#Array1) {
print "$Array1[$_] $Array2[$_] $Array3[$_]\n"
}

jue
 
B

Brad Baxter

I'm REALLY lost on getting this to work maybe someone can help me I have
three arrays that look like this:

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

and I want to output this format:

john car red
bill house blue
peter motorcycle green
james house teal


The Array::Each module will do this ...

use strict;
use warnings;
use Array::Each;

my @Array1 = qw(john bill peter james);
my @Array2 = qw(car house motorcycle house);
my @Array3 = qw(red blue green teal);

my $set = Array::Each->new( \( @Array1, @Array2, @Array3 ) );

while( my( $dude, $moneysink, $color ) = $set->each ) {
print "$dude $moneysink $color\n";
}

__END__
john car red
bill house blue
peter motorcycle green
james house teal


http://search.cpan.org/~bbaxter/Array-Each-0.02/Each.pm

Regards,

Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top