in reply to Get an input file and print multiple output files after performing operations on array.

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,

  • Comment on Re: Get an input file and print multiple output files after performing operations on array.
  • Select or Download Code