Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Printing from three arrays

by Discipulus (Canon)
on Sep 26, 2019 at 08:55 UTC ( [id://11106725]=note: print w/replies, xml ) Need Help??


in reply to Printing from three arrays

Hello oysterperl and welcome to the monastery and to the wonderful world of perl!

You start with @array1 but I think is better to cycle @array2 which seems governing your output.

use strict; use warnings; my @array1 = (1..5); my @array2 = ('a','b','c','d','e','f','g'); my @array3 = ('I', 'II', 'III'); foreach my $letter(@array2){ foreach my $index_roman(0..$#array3){ foreach my $index (0..$#array1){ print "$array1[$index],$letter,$array3[$index_roman]\n"; } } }

PS as wisely said by hippo, cycling indexes is no more needed, so semplified nested loop will be:

foreach my $letter(@array2){ foreach my $roman(@array3){ foreach my $number (@array1){ print "$number,$letter,$roman\n"; } } }

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11106725]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found