Hello Ganesh Bharadwaj1, and welcome to the Monastery!

BrowserUk has answered your question; but, in case you ever need a more general solution, tye’s module Algorithm::Loops provides the NestedLoops function for this kind of task:

#! perl use strict; use warnings; use Algorithm::Loops qw( NestedLoops ); use Data::Dump; my @AoA; while (<DATA>) { chomp; my @fields = split; push @AoA, \@fields; } dd \@AoA; NestedLoops ( [ @AoA[0 .. $#AoA] ], sub { print join(', ', @_), "\n"; }, ); __DATA__ Jakarta paris delhi singapore hot cold wet yes no cannotcomment black white

Output:

22:59 >perl 1500_SoPW.pl [ ["Jakarta", "paris", "delhi", "singapore"], ["hot", "cold", "wet"], ["yes", "no", "cannotcomment"], ["black", "white"], ] Jakarta, hot, yes, black Jakarta, hot, yes, white Jakarta, hot, no, black Jakarta, hot, no, white Jakarta, hot, cannotcomment, black Jakarta, hot, cannotcomment, white Jakarta, cold, yes, black Jakarta, cold, yes, white Jakarta, cold, no, black Jakarta, cold, no, white Jakarta, cold, cannotcomment, black Jakarta, cold, cannotcomment, white Jakarta, wet, yes, black Jakarta, wet, yes, white Jakarta, wet, no, black Jakarta, wet, no, white Jakarta, wet, cannotcomment, black Jakarta, wet, cannotcomment, white paris, hot, yes, black paris, hot, yes, white paris, hot, no, black paris, hot, no, white paris, hot, cannotcomment, black paris, hot, cannotcomment, white paris, cold, yes, black paris, cold, yes, white paris, cold, no, black paris, cold, no, white paris, cold, cannotcomment, black paris, cold, cannotcomment, white paris, wet, yes, black paris, wet, yes, white paris, wet, no, black paris, wet, no, white paris, wet, cannotcomment, black paris, wet, cannotcomment, white delhi, hot, yes, black delhi, hot, yes, white delhi, hot, no, black delhi, hot, no, white delhi, hot, cannotcomment, black delhi, hot, cannotcomment, white delhi, cold, yes, black delhi, cold, yes, white delhi, cold, no, black delhi, cold, no, white delhi, cold, cannotcomment, black delhi, cold, cannotcomment, white delhi, wet, yes, black delhi, wet, yes, white delhi, wet, no, black delhi, wet, no, white delhi, wet, cannotcomment, black delhi, wet, cannotcomment, white singapore, hot, yes, black singapore, hot, yes, white singapore, hot, no, black singapore, hot, no, white singapore, hot, cannotcomment, black singapore, hot, cannotcomment, white singapore, cold, yes, black singapore, cold, yes, white singapore, cold, no, black singapore, cold, no, white singapore, cold, cannotcomment, black singapore, cold, cannotcomment, white singapore, wet, yes, black singapore, wet, yes, white singapore, wet, no, black singapore, wet, no, white singapore, wet, cannotcomment, black singapore, wet, cannotcomment, white 23:00 >

As you can see, this approach allows you to add another line to your input file without making any changes to your code!

Hope that’s of interest,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Get an input file and print multiple output files after performing operations on array. by Athanasius
in thread Get an input file and print multiple output files after performing operations on array. by Ganesh Bharadwaj1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.