This parses the data, I read it from the script for ease, you can uncomment your lines to read from the file again. If you have many folders it is probably better to make an array @folder to store the values for each one. Printing out to a file should be easy enough, open the file to write (> to start afresh, >> to append) and just print to the filehandle.
I assume the strings will be an exact match here, if case or spacing vary you may be better of with a regex in the tests, for instance if ($what=~/Main\s+folder\s+name/i) will allow variable spacing and case.
#!/usr/bin/perl
use warnings;
use strict;
my ($log_file,
$folder_1,
$folder_2,
$folder_3);
# open INFO_FILE "<D:\\prad\\test\\info.txt";
# while<INFO_FILE>{
while (<DATA>) {
next unless /:/; # ignore lines without the : seperator
chomp; # remove new line characters
my ($what, $data)=split ":";
if ($what eq "Log_file_name") {
$log_file=$data;
} elsif ($what eq "Main folder name") {
$folder_1=$data;
} elsif ($what eq "Second folder name") {
$folder_2=$data;
} elsif ($what eq "Third folder name") {
$folder_3=$data
}
}
# close INFO_FILE;
print "in file: $log_file, I found folders $folder_1, $folder_2, $fold
+er_3\n";
__DATA__
Log_file_name:XXXX.csv
Main folder name:Eitv9
Second folder name:Eitv9cmd_cln
Third folder name:Eitv9gsd_cln
Cheers, R.
Pereant, qui ante nos nostra dixerunt!
|