Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array combination

Status
Not open for further replies.

PerlElvir

Technical User
Aug 23, 2005
68
Hi all,

I have 2 x 3 array so I need to make combination between to get link

example:

my @year=("1year","2year");
my @month=("1month","2month");
my @day_1=("1day");

------

my @name=("1name","2name");
my @fruit=("1fruit","2fruit");
my @day_2=("2day");

-------

SO I need to get this:

link = 1year-1month-1day-1name-1fruit-2day
link = 1year-1month-1day-2name-2fruit-2day
link = 2year-2month-1day-1name-1fruit-2day
link = 2year-2month-1day-2name-2fruit-2day



Elvir,
 
It seems too obvious to me so maybe I'm missing something but what about this:
Code:
for(my $i=0; $i<=$#year; $i++) {
  print "$year[$i]-$month[$i]-$day_1[$i]-",
        "$name[$i]-$fruit[$i]-$day_2[$i]\n";
}


Trojan.
 
Thx Trojan , but now with this yours code I get this:


1year-1month-1day-1name-1fruit-2day
2year-2month--2name-2fruit-


but I need to have 4 combination:

1year-1month-1day-1name-1fruit-2day
1year-1month-1day-2name-2fruit-2day
2year-2month-1day-1name-1fruit-2day
2year-2month-1day-2name-2fruit-2day
 
Hi, PerlElvir.

Like Trojan, maybe I'm missing something but what about this:

Code:
my @year=("1year","2year");
my @month=("1month","2month");
my @day_1=("1day");

my @name=("1name","2name");
my @fruit=("1fruit","2fruit");
my @day_2=("2day");

for $m1 (0..$#year)
{
    for $m2 (0..$#name)
    {
	print "$year[$m1]-$month[$m1]-$day_1[0]-$name[$m2]-$fruit[$m2]-$day_2[0]\n";
    }
}

This code prints out the four as what you stated.

I just wonder if
1year-2month-1day-1name-2fruit-2day
2year-1month-1day-2name-1fruit-2day

are needed.

Good Luck.
eewah
 

Thx you all special to you eewah ;) Im get what I need

1year-1month-1day-1name-1fruit-2day
1year-1month-1day-2name-2fruit-2day
2year-2month-1day-1name-1fruit-2day
2year-2month-1day-2name-2fruit-2day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top