Ganesh Bharadwaj1 has asked for the wisdom of the Perl Monks concerning the following question:
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
One sample output file will look likeDelhi Beijing Canberra NewYork hot cold rainy go dontgo cannotcomment
another will look likeCity : Delhi Weather : hot recommended : go
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 :City : Delhi Weather : hot recommended : dontgo
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?syntax error at perl_script.pl line 8, near ") or"
#! 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; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perform array manipulation and save files in different directories.
by 1nickt (Canon) on Dec 30, 2015 at 03:33 UTC | |
by Ganesh Bharadwaj1 (Sexton) on Dec 30, 2015 at 09:23 UTC | |
|
Re: perform array manipulation and save files in different directories. syntax error at perl_script.pl line 8, near ")
by Anonymous Monk on Dec 30, 2015 at 02:53 UTC |