dear monks. I have a file in which I am getting the input from. I wish to generate output files and store these output files in different folders. as in out1.txt should be stored in directory1 and out2.txt needs to be stored in directory2 and so on. Using the current code I am able to create all possible combinations of the values present in my input code and put them in different files. My input file looks like

Delhi Beijing Canberra NewYork hot cold rainy go dontgo cannotcomment
One sample output file will look like
City : Delhi Weather : hot recommended : go
another will look like
City : Delhi Weather : hot recommended : dontgo
I want to print all possible combinations of the of city, weather and recommended , and the code below does that. But I also want to take each output file and put it in a different folder. Which is where I am having the issue. I think I should use the makepath keyword and use it inside the loop. But once I use the use File::Path, it gives the error :
syntax error at perl_script.pl line 8, near ") or"
Line 8 just opens the file for input. This is why I am confused. Could you please help let me know how I can modify the code to put the files in different folders?
#! perl -slw use strict; use Data::Dumper; #use File::Path open(my $in, '<', 'ocean_dummy') or die "Cannot open input.txt: $!"; my @city = split ' ', <$in>; my @temp = split ' ', <$in>; my @note = split ' ', <$in>; #perl -MFile::Path -e 'mkpath([map { "dir$_" } (1 .. 20)])' #-e 'mkpath([map { "dir$_" } (1 .. 20)])' #mkpath([map { "dir$_" } (1 .. 20)]); my $i = '01'; for my $city ( @city ) { for my $temp ( @temp ) { for my $note ( @note ) { #mkdir directory_$city$temp$note open O, '>', 'out' . $i++ or die $!; print O 'city: ', $city; print O 'weather: ', $temp; print O 'recommended: ', $note; close O; } } }

In reply to perform array manipulation and save files in different directories. 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.